diff --git a/modules/unicodejs/unicodejs.wordbreak.js b/modules/unicodejs/unicodejs.wordbreak.js index f6a9e3c2e8..910038d475 100644 --- a/modules/unicodejs/unicodejs.wordbreak.js +++ b/modules/unicodejs/unicodejs.wordbreak.js @@ -23,6 +23,12 @@ } function getGroup( chr ) { + // chr is always converted to a string by RegExp#test + // e.g. null -> 'null' and would match /[a-z]/ + // so return null for any non-string value + if ( typeof chr !== 'string' ) { + return null; + } var group; for ( group in patterns ) { if ( patterns[group].test( chr ) ) { diff --git a/modules/unicodejs/unicodejs.wordbreak.test.js b/modules/unicodejs/unicodejs.wordbreak.test.js index 769e610262..ca33b2622f 100644 --- a/modules/unicodejs/unicodejs.wordbreak.test.js +++ b/modules/unicodejs/unicodejs.wordbreak.test.js @@ -22,7 +22,7 @@ QUnit.test( 'isBreak', function ( assert ) { // 40 - 50 "汉字/漢字 c\u0300\u0327k" + // 50 - 60 - " c\u0300\u0327", + " c\u0300\u0327 a.", /*jshint quotmark:single */ textString = new unicodeJS.TextString( text ), breaks = [ @@ -31,7 +31,7 @@ QUnit.test( 'isBreak', function ( assert ) { 21, 25, 30, 31, 39, 40, 41, 42, 43, 44, 45, 46, 50, - 51, 54 + 51, 54, 55, 56, 57 ]; QUnit.expect( text.length + 1 );