Commit f738b87c authored by Chris Withers's avatar Chris Withers

- Collector #2061: Fix problems where windows line endings are passed to restricted code compilers.

parent a8bc52fa
......@@ -18,6 +18,9 @@ Zope Changes
Bugs fixed
- Collector #2061: Fix problems where windows line endings are passed
to restricted code compilers.
- Collector #2072: Applied patch to fix problem with overly restrictive
__bobo_traverse__ security and tests.
......
......@@ -42,6 +42,8 @@ class RestrictedCompileMode(AbstractCompileMode):
# See concrete subclasses below.
def __init__(self, source, filename):
if source:
source = '\n'.join(source.splitlines())
self.rm = RestrictionMutator()
AbstractCompileMode.__init__(self, source, filename)
......@@ -206,6 +208,8 @@ class RFunction(RModule):
def __init__(self, p, body, name, filename, globals):
self.params = p
if body:
body = '\n'.join(body.splitlines())
self.body = body
self.name = name
self.globals = globals or []
......
......@@ -499,6 +499,35 @@ class RestrictionTests(unittest.TestCase):
self.assertRaises(SyntaxError,
compile_restricted, err, "<string>", "exec")
# these two tests check that source code with Windows line
# endings still works.
def checkLineEndingsRFunction(self):
from RestrictedPython.RCompile import RFunction
gen = RFunction(
p='',
body='# testing\r\nprint "testing"\r\nreturn printed\n',
name='test',
filename='<test>',
globals=(),
)
gen.mode = 'exec'
# if the source has any line ending other than \n by the time
# parse() is called, then you'll get a syntax error.
gen.parse()
def checkLineEndingsRestrictedCompileMode(self):
from RestrictedPython.RCompile import RestrictedCompileMode
gen = RestrictedCompileMode(
'# testing\r\nprint "testing"\r\nreturn printed\n',
'<testing>'
)
gen.mode='exec'
# if the source has any line ending other than \n by the time
# parse() is called, then you'll get a syntax error.
gen.parse()
create_rmodule()
def test_suite():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment