Added better strict JS tests. Thanks @robhudson for pointing this out
This commit is contained in:
Родитель
2c542caa69
Коммит
df1cc03b18
|
@ -1,5 +1,5 @@
|
||||||
import copy
|
import copy
|
||||||
import json
|
import simplejson as json
|
||||||
import types
|
import types
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ class WebappSpec(Spec):
|
||||||
|
|
||||||
def parse(self, data):
|
def parse(self, data):
|
||||||
if isinstance(data, types.StringTypes):
|
if isinstance(data, types.StringTypes):
|
||||||
return json.loads(data)
|
return json.loads(data, strict=True)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def validate_root_node(self, root):
|
def validate_root_node(self, root):
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
|
from simplejson import JSONDecodeError
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from nose.tools import eq_, nottest
|
from nose.tools import eq_, nottest, raises
|
||||||
|
|
||||||
from appvalidator.errorbundle import ErrorBundle
|
from appvalidator.specs.webapps import WebappSpec
|
||||||
from appvalidator.errorbundle.outputhandlers.shellcolors import OutputHandler
|
|
||||||
import appvalidator.unicodehelper
|
|
||||||
import appvalidator.testcases.scripting
|
import appvalidator.testcases.scripting
|
||||||
|
import appvalidator.unicodehelper
|
||||||
from helper import TestCase
|
from helper import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,3 +50,14 @@ class TestControlChars(TestCase):
|
||||||
self.run_test("tests/resources/controlchars/controlchars_utf-8_warn.js")
|
self.run_test("tests/resources/controlchars/controlchars_utf-8_warn.js")
|
||||||
self.assert_failed(with_warnings=True)
|
self.assert_failed(with_warnings=True)
|
||||||
eq_(self.err.warnings[0]["id"][2], "syntax_error")
|
eq_(self.err.warnings[0]["id"][2], "syntax_error")
|
||||||
|
|
||||||
|
@raises(JSONDecodeError)
|
||||||
|
def test_controlchar_in_webapp(self):
|
||||||
|
"""
|
||||||
|
Test that unescaped control characters cause parse errors in the webapp
|
||||||
|
spec.
|
||||||
|
"""
|
||||||
|
|
||||||
|
data = '''{"foo":"%s"}''' % chr(7) # Bell!
|
||||||
|
self.setup_err()
|
||||||
|
webapp = WebappSpec(data, self.err)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче