Skip to content

Commit

Permalink
fix error if a SyntaxError is raised, but no text is provided (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
loechel committed Oct 3, 2018
1 parent 42b4be0 commit ecf62c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/RestrictedPython/compile.py
Expand Up @@ -60,7 +60,7 @@ def _compile_restricted_mode(
lineno=v.lineno,
type=v.__class__.__name__,
msg=v.msg,
statement=v.text.strip()
statement=v.text.strip() if v.text else None
))
if c_ast:
policy_instance = policy(
Expand Down
11 changes: 11 additions & 0 deletions tests/test_compile.py
Expand Up @@ -31,6 +31,17 @@ def test_compile__compile_restricted_invalid_mode_input():
compile_restricted("pass", '<string>', 'invalid')


INVALID_ASSINGMENT = """
1 = 2
"""


def test_compile__invalid_syntax():
with pytest.raises(SyntaxError) as err:
compile_restricted(INVALID_ASSINGMENT, '<string>', 'exec')
assert "can't assign to literal at statement:" in str(err.value)


@pytest.mark.parametrize(*c_exec)
def test_compile__compile_restricted_exec__1(c_exec):
"""It returns a CompileResult on success."""
Expand Down

0 comments on commit ecf62c5

Please sign in to comment.