Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for JSWrapper leak in jstypes

  • Loading branch information...
commit 55102e5bc46ee50b2f2941ab49e4cb72756e7b3a 1 parent a61300a
@mattbasta mattbasta authored
View
25 tests/test_js_jstypes.py
@@ -1,3 +1,5 @@
+from nose.tools import eq_
+
import validator.testcases.javascript.jstypes as jstypes
from js_helper import _do_test_raw
@@ -71,3 +73,26 @@ def test_jsarray_contsructor():
x["zap"] = "foo";
baz("zap" in x);
""").failed()
+
+
+def test_jsobject_get_wrap():
+ """Test that JSObject always returns a JSWrapper."""
+
+ x = jstypes.JSObject()
+ x.data["foo"] = jstypes.JSLiteral("bar")
+
+ out = x.get("foo")
+ assert isinstance(out, jstypes.JSWrapper)
+ eq_(out.get_literal_value(), "bar")
+
+
+def test_jsarray_get_wrap():
+ """Test that JSArray always returns a JSWrapper."""
+
+ x = jstypes.JSArray()
+ x.elements = [None, jstypes.JSLiteral("bar")]
+
+ out = x.get("1")
+ assert isinstance(out, jstypes.JSWrapper)
+ eq_(out.get_literal_value(), "bar")
+
View
7 validator/testcases/javascript/jstypes.py
@@ -46,6 +46,8 @@ def get(self, name, instantiate=False, traverser=None):
if output is None:
return JSWrapper(JSObject(), dirty=True, traverser=traverser)
+ if not isinstance(output, JSWrapper):
+ output = JSWrapper(output, traverser=traverser)
return output
def get_literal_value(self):
@@ -456,7 +458,10 @@ def get(self, index, instantiate=False, traverser=None):
# Courtesy of Ian Bicking: http://bit.ly/hxv6qt
try:
- return self.elements[int(index.strip().split()[0])]
+ output = self.elements[int(index.strip().split()[0])]
+ if not isinstance(output, JSWrapper):
+ output = JSWrapper(output, traverser=traverser)
+ return output
except (ValueError, IndexError, KeyError):
return super(JSArray, self).get(index, instantiate, traverser)
Please sign in to comment.
Something went wrong with that request. Please try again.