summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAleš Smodiš <aless@guru.si>2015-09-22 09:39:42 +0200
committerAleš Smodiš <aless@guru.si>2015-09-22 09:39:42 +0200
commit850f7a98c657f68b69c72cf7a369541cd3bbefc2 (patch)
treee8292afecbc40267bcf0e8cc17565a9f9211ce94 /js
parent20a9bac2cb976ea385f8c3bb530e2d9ae2972e71 (diff)
Make codeq.codePointCount() resilient to erraneous parameters.
Diffstat (limited to 'js')
-rw-r--r--js/codeq.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/js/codeq.js b/js/codeq.js
index e6a8a90..0ff78b2 100644
--- a/js/codeq.js
+++ b/js/codeq.js
@@ -716,8 +716,20 @@ window.phandler = null; // TODO: this is for debug only
*/
codeq.codePointCount = function (s) {
var n = 0, i, code;
+ if (typeof s !== 'string') {
+ code = 'codePointCount(): argument not a string: type = ' + typeof s + ', is null = ' + (s === null);
+ if ((typeof s === 'object') && (s !== null) && s.constructor) code += ', constructor = ' + s.constructor.name;
+ codeq.log.error(code);
+ return 0;
+ }
for (i = s.length - 1; i >= 0; i--) {
- code = s.charCodeAt(i);
+ try {
+ code = s.charCodeAt(i);
+ }
+ catch (e) {
+ codeq.log.error('Invocation of charCodeAt() failed at iteration #' + i + ': ' + e, e);
+ return 0;
+ }
if ((code >= 0xd800) && (code < 0xe000)) i++;
n++;
}