limit content size when using percent parser detection; fixes #320

This commit is contained in:
Mottie 2013-06-04 17:09:16 -05:00
parent 59dd43b279
commit 934b9cb9b5
2 changed files with 3 additions and 3 deletions

View File

@ -1360,7 +1360,7 @@
ts.addParser({
id: "percent",
is: function(s) {
return (/(\d\s?%|%\s?\d)/).test(s);
return (/(\d\s*?%|%\s*?\d)/).test(s) && s.length < 15;
},
format: function(s, table) {
return s ? ts.formatFloat(s.replace(/%/g, ""), table) : s;

View File

@ -209,7 +209,7 @@
************************************************/
var p = ts.parsers,
// test by parser
parserTests = 84,
parserTests = 85,
// skipping metadata parser
sample1 = {
'text' : { 'test': 'test', 'TesT': 'test', '\u00e1 test': 'á test' },
@ -217,7 +217,7 @@
'ipAddress' : { '255.255.255.255': 255255255255, '32.32.32.32': 32032032032, '1.1.1.1': 1001001001 },
'url' : { 'http://google.com': 'google.com', 'ftp://fred.com': 'fred.com', 'https://github.com': 'github.com' },
'isoDate' : { '2012/12/12': 1355292000000, '2012-12/12': 1355292000000, '2013-1-1': 1357020000000, '2013/1/1 12:34:56 AM': 1357022096000 },
'percent' : { '100%': 100, '22%': 22, '%2': 2, '2 %': 2, '(4%)': -4 },
'percent' : { '100%': 100, '22%': 22, '%2': 2, '2 %': 2, '(4%)': -4, '1,234.56 %': 1234.56 },
'usLongDate': { 'Feb 23, 1999': 919749600000, 'Feb 23, 1999 12:34': 919794840000, 'Feb 23, 1999 12:34 AM': 919751640000, 'Feb 23, 1999 12:34:56 PM': 919794896000, '01 Jan 2013': 1357020000000 },
'shortDate' : { '1/2/2001': 978415200000, '1 2 2001': 978415200000, '1.2.2001': 978415200000, '1-2-2001': 978415200000, '1/2/2001 12:34 PM' : 978460440000, '1.2.2001 13:34' : 978464040000 },
'time' : { '12:34 AM': 946708440000, '1:00 pm': 946753200000 },