summaryrefslogtreecommitdiff
path: root/cgi-bin/js_check/test_javascript.py.bk
diff options
context:
space:
mode:
authorpepper <peppersclothescult@gmail.com>2014-01-12 19:47:18 -0800
committerpepper <peppersclothescult@gmail.com>2014-01-12 19:47:18 -0800
commite5b7549dbe43872f1cd0d8395186ad8e495720fb (patch)
tree356239d88572247479985612942eb1233da0bc12 /cgi-bin/js_check/test_javascript.py.bk
parentcce4f73a1637d54ab7c096815864a2c9c66fda65 (diff)
added upload stuff and view code
Diffstat (limited to 'cgi-bin/js_check/test_javascript.py.bk')
-rw-r--r--cgi-bin/js_check/test_javascript.py.bk85
1 files changed, 85 insertions, 0 deletions
diff --git a/cgi-bin/js_check/test_javascript.py.bk b/cgi-bin/js_check/test_javascript.py.bk
new file mode 100644
index 0000000..31ecaa6
--- /dev/null
+++ b/cgi-bin/js_check/test_javascript.py.bk
@@ -0,0 +1,85 @@
+#!/usr/bin/python2
+import jsparser, re, sys, types, getopt
+import cgi
+import cgitb
+print 'Content-type: text/html\n\n'
+cgitb.enable()
+RESERVED_WORDLIST = ['document',
+ 'window',
+ 'alert',
+ 'console',
+ '$',
+ 'jQuery',
+ 'xmlhttp',
+ 'eval',
+ 'XMLHttpRequest',
+ 'String',
+ 'this']
+form = cgi.FieldStorage()
+opt_v = False
+if 'script' not in form:
+ print '<h1>script not found</h1>'
+ sys.exit(1)
+else:
+ print 'loading %d bytes' % len(form['script'].value)
+test = jsparser.parse(form['script'].value)
+ITERATION_BLOCKS = ['expression',
+ 'body',
+ 'block',
+ 'initializer',
+ 'condition',
+ 'thenPart',
+ 'elsePart',
+ 'tryBlock',
+ 'catchClauses',
+ 'varDecls']
+
+def test_script(tree, rec_level = 1):
+ if opt_v:
+ print 'test_script(tree,%d)' % rec_level
+ for i, v in enumerate(tree):
+ if v.type == 'IDENTIFIER' and v.value in RESERVED_WORDLIST:
+ print '(MY) ERROR reserved word "%s" used in assignment at line number %s' % (v.value, v.lineno)
+ sys.exit(1)
+ if v.type == 'STRING':
+ print '(MY) ERROR illegal type "%s" used at line number %s' % (v.type, v.lineno)
+ sys.exit(1)
+ if opt_v:
+ print 'this is the type: %s at line number %s' % (v.type, v.lineno)
+ if opt_v:
+ print 'this is the value: %s at line number %s' % (v.value, v.lineno)
+ test_script(v, rec_level + 1)
+
+ for block in ITERATION_BLOCKS:
+ if hasattr(tree, block):
+ b = getattr(tree, block)
+ try:
+ if opt_v:
+ print ' this is the expression type: %s ' % getattr(b, 'type')
+ except Exception as e:
+ sys.stderr.write('this was the error %s ' % e)
+ continue
+
+ try:
+ for i, v in enumerate(b):
+ if b.type == 'PLUS' and v.type == 'ARRAY_INIT':
+ print '(MY) ERROR illegal use of arrays to cast strings at %s' % v.lineno
+ sys.exit(1)
+ if opt_v:
+ print 'this is the (inner iteration) type: %s, at line number %s, rec_lev: %d' % (v.type, v.lineno, rec_level)
+ if v.type == 'STRING':
+ print '(MY) ERROR illegal type "%s" used at line number %s' % (v.type, v.lineno)
+ sys.exit(1)
+ if opt_v:
+ print 'this is the (inner iteration) value: %s' % v.value
+ test_script(v, rec_level + 1)
+
+ except Exception as e:
+ sys.stderr.write('this was the error %s ' % e)
+ continue
+
+ if opt_v:
+ print 'test_script(tree,%d) end' % rec_level
+
+
+test_script(test)