OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2014 Google Inc. All rights reserved. | 2 # Copyright (c) 2014 Google Inc. All rights reserved. |
3 # | 3 # |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 # - instanceof, since e.g. "obj instanceof Error" may throw if Error is over ridden and is not a function | 56 # - instanceof, since e.g. "obj instanceof Error" may throw if Error is over ridden and is not a function |
57 # - Object.prototype.toString() | 57 # - Object.prototype.toString() |
58 # - Array.prototype.* | 58 # - Array.prototype.* |
59 # - Function.prototype.* | 59 # - Function.prototype.* |
60 # - Math.* | 60 # - Math.* |
61 # - Global functions | 61 # - Global functions |
62 black_list_call_regex = re.compile(r"\sinstanceof\s+\w*|\bMath\.\w+\(|(?<!In jectedScriptHost)\.(" + proto_functions + r")\(|[^\.]\b(" + global_functions + r ")\(") | 62 black_list_call_regex = re.compile(r"\sinstanceof\s+\w*|\bMath\.\w+\(|(?<!In jectedScriptHost)\.(" + proto_functions + r")\(|[^\.]\b(" + global_functions + r ")\(") |
63 | 63 |
64 errors_found = False | 64 errors_found = False |
65 for i, line in enumerate(lines): | 65 for i, line in enumerate(lines): |
66 if line.find("suppressBlacklist"): | |
kozy
2016/08/10 17:17:11
find in python returns -1 if not found :(
| |
67 continue | |
66 for match in re.finditer(black_list_call_regex, line): | 68 for match in re.finditer(black_list_call_regex, line): |
67 errors_found = True | 69 errors_found = True |
68 print "ERROR: Black listed expression in %s at line %02d column %02d : %s" % (os.path.basename(fileName), i + 1, match.start(), match.group(0)) | 70 print "ERROR: Black listed expression in %s at line %02d column %02d : %s" % (os.path.basename(fileName), i + 1, match.start(), match.group(0)) |
69 | 71 |
70 if not errors_found: | 72 if not errors_found: |
71 print "OK" | 73 print "OK" |
72 | 74 |
73 | 75 |
74 def main(argv): | 76 def main(argv): |
75 if len(argv) < 2: | 77 if len(argv) < 2: |
76 print('ERROR: Usage: %s path/to/InjectedScriptSource.js' % argv[0]) | 78 print('ERROR: Usage: %s path/to/InjectedScriptSource.js' % argv[0]) |
77 return 1 | 79 return 1 |
78 | 80 |
79 validate_injected_script(argv[1]) | 81 validate_injected_script(argv[1]) |
80 | 82 |
81 if __name__ == '__main__': | 83 if __name__ == '__main__': |
82 sys.exit(main(sys.argv)) | 84 sys.exit(main(sys.argv)) |
OLD | NEW |