Added better strict JS tests. Thanks @robhudson for pointing this out

This commit is contained in:
Matt Basta 2012-08-20 13:02:05 -07:00
Родитель 2c542caa69
Коммит df1cc03b18
2 изменённых файлов: 17 добавлений и 6 удалений

Просмотреть файл

@ -1,5 +1,5 @@
import copy
import json
import simplejson as json
import types
import urlparse
@ -267,7 +267,7 @@ class WebappSpec(Spec):
def parse(self, data):
if isinstance(data, types.StringTypes):
return json.loads(data)
return json.loads(data, strict=True)
return data
def validate_root_node(self, root):

Просмотреть файл

@ -1,11 +1,11 @@
from simplejson import JSONDecodeError
import sys
from nose.tools import eq_, nottest
from nose.tools import eq_, nottest, raises
from appvalidator.errorbundle import ErrorBundle
from appvalidator.errorbundle.outputhandlers.shellcolors import OutputHandler
import appvalidator.unicodehelper
from appvalidator.specs.webapps import WebappSpec
import appvalidator.testcases.scripting
import appvalidator.unicodehelper
from helper import TestCase
@ -50,3 +50,14 @@ class TestControlChars(TestCase):
self.run_test("tests/resources/controlchars/controlchars_utf-8_warn.js")
self.assert_failed(with_warnings=True)
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)