mirror of https://github.com/svaarala/duktape.git
Sami Vaarala
9 years ago
4 changed files with 125 additions and 15 deletions
@ -0,0 +1,10 @@ |
|||
define: DUK_USE_NONSTD_REGEXP_BRACES |
|||
feature_enables: DUK_OPT_NONSTD_REGEXP_BRACES |
|||
introduced: 1.3.2 |
|||
default: true |
|||
tags: |
|||
- ecmascript |
|||
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. |
@ -0,0 +1,75 @@ |
|||
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); |
|||
} |
Loading…
Reference in new issue