diff --git a/appvalidator/testcases/javascript/actions.py b/appvalidator/testcases/javascript/actions.py index bc8e6c4..d254fb5 100644 --- a/appvalidator/testcases/javascript/actions.py +++ b/appvalidator/testcases/javascript/actions.py @@ -395,7 +395,7 @@ def _call_expression(traverser, node): if member.is_global and "return" in member.value: return member.value["return"](wrapper=member, arguments=args, traverser=traverser) - return True + return JSWrapper(traverser=traverser) def _call_settimeout(a, t, e): diff --git a/appvalidator/testcases/javascript/instanceproperties.py b/appvalidator/testcases/javascript/instanceproperties.py index 6e839e9..60ae540 100644 --- a/appvalidator/testcases/javascript/instanceproperties.py +++ b/appvalidator/testcases/javascript/instanceproperties.py @@ -5,6 +5,10 @@ from appvalidator.constants import BUGZILLA_BUG import jstypes +EVENT_ASSIGNMENT = re.compile("<.+ on[a-z]+=") +JS_URL = re.compile("href=[\'\"]javascript:") + + def set_innerHTML(new_value, traverser): """Tests that values being assigned to innerHTML are not dangerous.""" return _set_HTML_property("innerHTML", new_value, traverser) @@ -24,9 +28,8 @@ def _set_HTML_property(function, new_value, traverser): if isinstance(literal_value, types.StringTypes): # Static string assignments - # Test for on* attributes - event_assignment = re.compile("<.+ on[a-z]+=") - if event_assignment.search(literal_value.lower()): + # Test for on* attributes and script tags. + if EVENT_ASSIGNMENT.search(literal_value.lower()): traverser.err.warning( err_id=("testcases_javascript_instancetypes", "set_%s" % function, "event_assignment"), @@ -41,6 +44,21 @@ def _set_HTML_property(function, new_value, traverser): line=traverser.line, column=traverser.position, context=traverser.context) + elif (" ") if line == "enable bootstrap\n": err.save_resource("em:bootstrap", True) continue @@ -73,7 +73,7 @@ if __name__ == '__main__': print actions[vars[0]](wrap) continue - tree = spidermonkey.get_tree(line, err) + tree = spidermonkey.get_tree(line, err, shell=SPIDERMONKEY_INSTALLATION) if tree is None: continue tree = tree["body"] diff --git a/tests/js/test_instanceproperties.py b/tests/js/test_instanceproperties.py index b32812e..266d0ac 100644 --- a/tests/js/test_instanceproperties.py +++ b/tests/js/test_instanceproperties.py @@ -1,6 +1,12 @@ +from mock import patch + from js_helper import _do_test_raw, TestCase +def _mock_html_error(self, *args, **kwargs): + self.err.error(("foo", "bar"), "Does not pass validation.") + + class TestHTML(TestCase): def test_innerHTML(self): @@ -19,6 +25,8 @@ class TestHTML(TestCase): yield test, self, decl, '"
"', False yield test, self, decl, '"
"', True yield test, self, decl, '"x" + y', True + yield test, self, decl, '', True + yield test, self, decl, '""; + x.innerHTML = ""; """) self.assert_failed(with_errors=True) + def test_function_return(self): + """ + Test that the return value of a function is considered a dynamic value. + """ + + self.run_script(""" + x.innerHTML = foo(); + """) + self.assert_failed() + class TestOnProperties(TestCase):