mirror of https://github.com/svaarala/duktape.git
Sami Vaarala
9 years ago
24 changed files with 293 additions and 129 deletions
@ -1,10 +1,12 @@ |
|||
define: DUK_USE_NONSTD_REGEXP_BRACES |
|||
feature_enables: DUK_OPT_NONSTD_REGEXP_BRACES |
|||
introduced: 1.3.2 |
|||
introduced: 1.5.0 |
|||
default: true |
|||
tags: |
|||
- ecmascript |
|||
- compliance |
|||
description: > |
|||
Enable support for non-standard '{' literal. Ecmascript requires |
|||
curly braces to be escaped, but most regex engine support them |
|||
when they are not used in valid quantifier. This option is recommended. |
|||
Enable support for non-standard '{' and '}' literals. Ecmascript requires |
|||
literal curly braces to be escaped, but most Ecmascript engines support them |
|||
when they are not used in valid quantifier. This option is recommended |
|||
because a lot of existing code depends on non-standard literal braces. |
|||
|
@ -0,0 +1,14 @@ |
|||
# Enable compliant behavior, defaults favor "real world" compatibility. |
|||
|
|||
DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER: false |
|||
DUK_USE_NONSTD_ARRAY_MAP_TRAILER: false |
|||
DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT: false |
|||
DUK_USE_NONSTD_FUNC_CALLER_PROPERTY: false |
|||
DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY: false |
|||
DUK_USE_NONSTD_FUNC_STMT: false |
|||
DUK_USE_NONSTD_GETTER_KEY_ARGUMENT: false |
|||
DUK_USE_NONSTD_JSON_ESC_U2028_U2029: false |
|||
DUK_USE_NONSTD_REGEXP_BRACES: false |
|||
DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE: false |
|||
DUK_USE_NONSTD_SETTER_KEY_ARGUMENT: false |
|||
DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT: false |
@ -0,0 +1,63 @@ |
|||
/* |
|||
* Duktape has an internal digit limit (9 digits) for regexp quantifier |
|||
* min/max counts. |
|||
*/ |
|||
|
|||
/*--- |
|||
{ |
|||
"custom": true |
|||
} |
|||
---*/ |
|||
|
|||
/*=== |
|||
["xxx"] |
|||
null |
|||
===*/ |
|||
|
|||
// 8 digits
|
|||
try { |
|||
print(eval("JSON.stringify(/x{3,99999999}/.exec('xxx'))")); |
|||
} catch (e) { |
|||
print(e); |
|||
} |
|||
try { |
|||
print(eval("JSON.stringify(/x{88888888,99999999}/.exec('xxx'))")); |
|||
} catch (e) { |
|||
print(e); |
|||
} |
|||
|
|||
/*=== |
|||
["xxx"] |
|||
null |
|||
===*/ |
|||
|
|||
// 9 digits, still accepted
|
|||
try { |
|||
print(eval("JSON.stringify(/x{3,999999999}/.exec('xxx'))")); |
|||
} catch (e) { |
|||
print(e); |
|||
} |
|||
try { |
|||
print(eval("JSON.stringify(/x{333333333,999999999}/.exec('xxx'))")); |
|||
} catch (e) { |
|||
print(e); |
|||
} |
|||
|
|||
/*=== |
|||
null |
|||
null |
|||
===*/ |
|||
|
|||
// 10 digits: SyntaxError without non-standard literal curly braces
|
|||
// (DUK_USE_NONSTD_REGEXP_BRACES), treated as a literal with non-standard
|
|||
// curly braces.
|
|||
try { |
|||
print(eval("JSON.stringify(/x{3,9999999999}/.exec('xxx'))")); |
|||
} catch (e) { |
|||
print(e); |
|||
} |
|||
try { |
|||
print(eval("JSON.stringify(/x{3333333333,9999999999}/.exec('xxx'))")); |
|||
} catch (e) { |
|||
print(e); |
|||
} |
@ -1,75 +0,0 @@ |
|||
var t; |
|||
|
|||
/*=== |
|||
a{abc} |
|||
a{1b} |
|||
a{2,b} |
|||
===*/ |
|||
|
|||
// Any non-valid character cancels quantifier parsing
|
|||
|
|||
t = /a{.*}/.exec("aa{abc}"); |
|||
print(t[0]); |
|||
t = /a{1.}/.exec("aa{1b}"); |
|||
print(t[0]); |
|||
t = /a{2,.}/.exec("aa{2,b}"); |
|||
print(t[0]); |
|||
|
|||
/*=== |
|||
a{abc} |
|||
===*/ |
|||
|
|||
// Closing brace is allowed
|
|||
t = /a\{.*}/.exec("aa{abc}"); |
|||
print(t[0]); |
|||
|
|||
/*=== |
|||
a{1} |
|||
a{1,2} |
|||
===*/ |
|||
|
|||
// Valid quantifier but for the closing brace
|
|||
t = /a{1\}/.exec("aa{1}"); |
|||
print(t[0]); |
|||
t = /a{1,2\}/.exec("aa{1,2}"); |
|||
print(t[0]); |
|||
|
|||
/*=== |
|||
{1111111111111111111111111 |
|||
===*/ |
|||
|
|||
// Do not fail on digits before , or }
|
|||
t = /{1111111111111111111111111/.exec('{1111111111111111111111111'); |
|||
print(t[0]); |
|||
|
|||
/*=== |
|||
a{} |
|||
a{,} |
|||
a{1,2,3} |
|||
===*/ |
|||
|
|||
//On parsing failure, treat as a brace
|
|||
|
|||
t = /a{}/.exec('a{}'); |
|||
print(t[0]); |
|||
|
|||
t = /a{,}/.exec('a{,}'); |
|||
print(t[0]); |
|||
|
|||
t = /a{1,2,3}/.exec('a{1,2,3}'); |
|||
print(t[0]); |
|||
|
|||
|
|||
/*=== |
|||
SyntaxError |
|||
===*/ |
|||
|
|||
// Current implementation does not allow all types of error
|
|||
|
|||
// Too many numbers
|
|||
try { |
|||
eval("/{1111111111111111111111111}/.exec('foo');"); |
|||
print("no exception"); |
|||
} catch (e) { |
|||
print(e.name); |
|||
} |
@ -0,0 +1,105 @@ |
|||
/* |
|||
* Ecmascript regexp pattern character production does not allow literal |
|||
* curly braces in any position, but many Ecmascript regexp engines allow |
|||
* them when the meaning is unambiguous. Since Duktape 1.5.0 Duktape also |
|||
* allows literal curly braces in regexps. |
|||
*/ |
|||
|
|||
// Behavior is custom because e.g. quantifier digit limits are Duktape specific.
|
|||
/*--- |
|||
{ |
|||
"custom": true |
|||
} |
|||
---*/ |
|||
|
|||
var t; |
|||
|
|||
/*=== |
|||
a{abc} |
|||
a{1b} |
|||
a{2,b} |
|||
===*/ |
|||
|
|||
// Any invalid character cancels quantifier parsing, and causes the left
|
|||
// curly brace to be treated as a literal (i.e. same as /\{/).
|
|||
|
|||
t = /a{.*}/.exec("aa{abc}"); |
|||
print(t[0]); |
|||
t = /a{1.}/.exec("aa{1b}"); |
|||
print(t[0]); |
|||
t = /a{2,.}/.exec("aa{2,b}"); |
|||
print(t[0]); |
|||
|
|||
/*=== |
|||
a{abc} |
|||
===*/ |
|||
|
|||
// Unescaped right (closing) brace is allowed anywhere outside a quantifier
|
|||
// because it's unambiguous.
|
|||
|
|||
t = /a\{.*}/.exec("aa{abc}"); |
|||
print(t[0]); |
|||
|
|||
/*=== |
|||
a{1} |
|||
a{1,2} |
|||
===*/ |
|||
|
|||
// Valid quantifier except for the closing brace: quantifier parsing is
|
|||
// cancelled and left curly brace is treated as a literal.
|
|||
|
|||
t = /a{1\}/.exec("aa{1}"); |
|||
print(t[0]); |
|||
t = /a{1,2\}/.exec("aa{1,2}"); |
|||
print(t[0]); |
|||
|
|||
/*=== |
|||
{1111111111111111111111111 |
|||
===*/ |
|||
|
|||
// Do not fail on digits before , or }.
|
|||
|
|||
t = /{1111111111111111111111111/.exec('{1111111111111111111111111'); |
|||
print(t[0]); |
|||
|
|||
/*=== |
|||
a{} |
|||
a{,} |
|||
a{1,2,3} |
|||
===*/ |
|||
|
|||
// On any quantifier parsing failure, treat as a literal brace.
|
|||
|
|||
t = /a{}/.exec('a{}'); |
|||
print(t[0]); |
|||
|
|||
t = /a{,}/.exec('a{,}'); |
|||
print(t[0]); |
|||
|
|||
t = /a{1,2,3}/.exec('a{1,2,3}'); |
|||
print(t[0]); |
|||
|
|||
/*=== |
|||
{1111111111111111111111111,} |
|||
{1111111111111111111111111,2222222222222222222222222222} |
|||
{1111,1111111111} |
|||
xxxxxxxxxxx |
|||
===*/ |
|||
|
|||
// Duktape has an internal limitation on the maximum number of quantifier
|
|||
// digits: in this case the limits are exceeded and the quantifier is
|
|||
// rejected and the curly brace is then parsed as a literal. At the moment
|
|||
// the maximum number of digits allowed for quantifier min/max value is 9.
|
|||
|
|||
t = /{1111111111111111111111111,}/.exec('{1111111111111111111111111,}foo'); |
|||
print(t[0]); |
|||
|
|||
t = /{1111111111111111111111111,2222222222222222222222222222}/.exec('{1111111111111111111111111,2222222222222222222222222222}'); |
|||
print(t[0]); |
|||
|
|||
t = /{1111,1111111111}/.exec('{1111,1111111111}foo'); |
|||
print(t[0]); |
|||
|
|||
// Here the max limit is exactly 9 digits so it's treated as a valid quantifier.
|
|||
t = /x{11,111111111}/.exec('xxxxxxxxxxx'); |
|||
print(t[0]); |
Loading…
Reference in new issue