mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 21:05:36 +00:00
Follow Perl 5, not ECMA-262 Ed 3 on unescaped, unbalanced brackets and braces. See bug 223273.
This commit is contained in:
parent
4bab03c0f6
commit
92ef5f7beb
@ -36,7 +36,18 @@
|
|||||||
*
|
*
|
||||||
* Date: 23 October 2003
|
* Date: 23 October 2003
|
||||||
* SUMMARY: Unescaped, unbalanced parens in a regexp should cause SyntaxError.
|
* SUMMARY: Unescaped, unbalanced parens in a regexp should cause SyntaxError.
|
||||||
* The same should also be true for unescaped, unbalanced brackets or braces.
|
*
|
||||||
|
* The same would also be true for unescaped, unbalanced brackets or braces
|
||||||
|
* if we followed the ECMA-262 Ed. 3 spec on this. But it was decided for
|
||||||
|
* backward compatibility reasons to follow Perl 5, which permits
|
||||||
|
*
|
||||||
|
* 1. an unescaped, unbalanced right bracket ]
|
||||||
|
* 2. an unescaped, unbalanced left brace {
|
||||||
|
* 3. an unescaped, unbalanced right brace }
|
||||||
|
*
|
||||||
|
* If any of these should occur, Perl treats each as a literal character.
|
||||||
|
* Therefore we permit all three of these cases, even though not ECMA-compliant.
|
||||||
|
* Note Perl errors on an unescaped, unbalanced left bracket; so will we.
|
||||||
*
|
*
|
||||||
* See http://bugzilla.mozilla.org/show_bug.cgi?id=223273
|
* See http://bugzilla.mozilla.org/show_bug.cgi?id=223273
|
||||||
*
|
*
|
||||||
@ -105,19 +116,25 @@ checkThis(' /(abc([x\\)yz]+)def)g/ ');
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Run similar tests as above for unbalanced brackets -
|
* Unescaped, unbalanced left brackets should be a SyntaxError
|
||||||
*/
|
*/
|
||||||
status = inSection(11);
|
status = inSection(11);
|
||||||
testThis(' /[/ ');
|
testThis(' /[/ ');
|
||||||
|
|
||||||
status = inSection(12);
|
status = inSection(12);
|
||||||
testThis(' /]/ ');
|
|
||||||
|
|
||||||
status = inSection(13);
|
|
||||||
testThis(' /[abc\\]def[g/ ');
|
testThis(' /[abc\\]def[g/ ');
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We permit unescaped, unbalanced right brackets, as does Perl.
|
||||||
|
* No error should result, even though this is not ECMA-compliant.
|
||||||
|
* Note we use checkThis() instead of testThis().
|
||||||
|
*/
|
||||||
|
status = inSection(13);
|
||||||
|
checkThis(' /]/ ');
|
||||||
|
|
||||||
status = inSection(14);
|
status = inSection(14);
|
||||||
testThis(' /\\[abc]def]g/ ');
|
checkThis(' /\\[abc]def]g/ ');
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -145,25 +162,41 @@ checkThis(' /[abc(x\\]yz+)def]g/ ');
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Run some tests for unbalanced braces -
|
* Run some tests for unbalanced braces. We again follow Perl, and
|
||||||
|
* thus permit unescaped unbalanced braces - both left and right,
|
||||||
|
* even though this is not ECMA-compliant.
|
||||||
|
*
|
||||||
|
* Note we use checkThis() instead of testThis().
|
||||||
*/
|
*/
|
||||||
status = inSection(21);
|
status = inSection(21);
|
||||||
testThis(' /abc{def/ ');
|
checkThis(' /abc{def/ ');
|
||||||
|
|
||||||
status = inSection(22);
|
status = inSection(22);
|
||||||
testThis(' /abc}def/ ');
|
checkThis(' /abc}def/ ');
|
||||||
|
|
||||||
|
status = inSection(23);
|
||||||
|
checkThis(' /a{2}bc{def/ ');
|
||||||
|
|
||||||
|
status = inSection(24);
|
||||||
|
checkThis(' /a}b{3}c}def/ ');
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These regexp patterns are correct and should not generate
|
* These regexp patterns are correct and should not generate
|
||||||
* any errors. Note we use checkThis() instead of testThis().
|
* any errors. Note we use checkThis() instead of testThis().
|
||||||
*/
|
*/
|
||||||
status = inSection(23);
|
status = inSection(25);
|
||||||
checkThis(' /abc\\{def/ ');
|
checkThis(' /abc\\{def/ ');
|
||||||
|
|
||||||
status = inSection(24);
|
status = inSection(26);
|
||||||
checkThis(' /abc\\}def/ ');
|
checkThis(' /abc\\}def/ ');
|
||||||
|
|
||||||
|
status = inSection(27);
|
||||||
|
checkThis(' /a{2}bc\\{def/ ');
|
||||||
|
|
||||||
|
status = inSection(28);
|
||||||
|
checkThis(' /a\\}b{3}c\\}def/ ');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user