Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: test/mjsunit/regress/regress-219.js

Issue 7624045: Make regexp flag parsing stricter. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/regexp.js ('k') | test/mjsunit/regress/regress-87.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Tests handling of flags for regexps. 28 // Tests handling of flags for regexps.
29 29
30 // We should now allow duplicates of flags. 30 // We should now allow duplicates of flags.
31 // (See http://code.google.com/p/v8/issues/detail?id=219) 31 // (See http://code.google.com/p/v8/issues/detail?id=219)
32 32
33 // This has been reversed by issue 1628, since other browsers have also
34 // tightened their syntax.
35 // (See http://code.google.com/p/v8/issues/detail?id=1628)
36
33 // Base tests: we recognize the basic flags 37 // Base tests: we recognize the basic flags
34 38
35 function assertFlags(re, global, multiline, ignoreCase) { 39 function assertFlags(re, global, multiline, ignoreCase) {
36 var name = re + " flag: "; 40 var name = re + " flag: ";
37 (global ? assertTrue : assertFalse)(re.global, name + "g"); 41 (global ? assertTrue : assertFalse)(re.global, name + "g");
38 (multiline ? assertTrue : assertFalse)(re.multiline, name + "m"); 42 (multiline ? assertTrue : assertFalse)(re.multiline, name + "m");
39 (ignoreCase ? assertTrue : assertFalse)(re.ignoreCase, name + "i"); 43 (ignoreCase ? assertTrue : assertFalse)(re.ignoreCase, name + "i");
40 } 44 }
41 45
42 var re = /a/; 46 var re = /a/;
43 assertFlags(re, false, false, false) 47 assertFlags(re, false, false, false)
44 48
45 re = /a/gim; 49 re = /a/gim;
46 assertFlags(re, true, true, true) 50 assertFlags(re, true, true, true)
47 51
48 re = RegExp("a",""); 52 re = RegExp("a","");
49 assertFlags(re, false, false, false) 53 assertFlags(re, false, false, false)
50 54
51 re = RegExp("a", "gim"); 55 re = RegExp("a", "gim");
52 assertFlags(re, true, true, true) 56 assertFlags(re, true, true, true)
53 57
54 // Double i's 58 // Double i's
55 59
56 re = /a/ii; 60 assertThrows("/a/ii");
57 assertFlags(re, false, false, true)
58 61
59 re = /a/gii; 62 assertThrows("/a/gii");
60 assertFlags(re, true, false, true)
61 63
62 re = /a/igi; 64 assertThrows("/a/igi");
63 assertFlags(re, true, false, true)
64 65
65 re = /a/iig; 66 assertThrows("/a/iig");
66 assertFlags(re, true, false, true)
67 67
68 re = /a/gimi; 68 assertThrows("/a/gimi");
69 assertFlags(re, true, true, true)
70 69
71 re = /a/giim; 70 assertThrows("/a/giim");
72 assertFlags(re, true, true, true)
73 71
74 re = /a/igim; 72 assertThrows("/a/igim");
75 assertFlags(re, true, true, true)
76 73
74 assertThrows(function(){ return RegExp("a", "ii"); })
77 75
78 re = RegExp("a", "ii"); 76 assertThrows(function(){ return RegExp("a", "gii"); })
79 assertFlags(re, false, false, true)
80 77
81 re = RegExp("a", "gii"); 78 assertThrows(function(){ return RegExp("a", "igi"); })
82 assertFlags(re, true, false, true)
83 79
84 re = RegExp("a", "igi"); 80 assertThrows(function(){ return RegExp("a", "iig"); })
85 assertFlags(re, true, false, true)
86 81
87 re = RegExp("a", "iig"); 82 assertThrows(function(){ return RegExp("a", "gimi"); })
88 assertFlags(re, true, false, true)
89 83
90 re = RegExp("a", "gimi"); 84 assertThrows(function(){ return RegExp("a", "giim"); })
91 assertFlags(re, true, true, true)
92 85
93 re = RegExp("a", "giim"); 86 assertThrows(function(){ return RegExp("a", "igim"); })
94 assertFlags(re, true, true, true)
95
96 re = RegExp("a", "igim");
97 assertFlags(re, true, true, true)
98 87
99 // Tripple i's 88 // Tripple i's
100 89
101 re = /a/iii; 90 assertThrows("/a/iii");
102 assertFlags(re, false, false, true)
103 91
104 re = /a/giii; 92 assertThrows("/a/giii");
105 assertFlags(re, true, false, true)
106 93
107 re = /a/igii; 94 assertThrows("/a/igii");
108 assertFlags(re, true, false, true)
109 95
110 re = /a/iigi; 96 assertThrows("/a/iigi");
111 assertFlags(re, true, false, true)
112 97
113 re = /a/iiig; 98 assertThrows("/a/iiig");
114 assertFlags(re, true, false, true)
115 99
116 re = /a/miiig; 100 assertThrows("/a/miiig");
117 assertFlags(re, true, true, true)
118 101
102 assertThrows(function(){ return RegExp("a", "iii"); })
119 103
120 re = RegExp("a", "iii"); 104 assertThrows(function(){ return RegExp("a", "giii"); })
121 assertFlags(re, false, false, true)
122 105
123 re = RegExp("a", "giii"); 106 assertThrows(function(){ return RegExp("a", "igii"); })
124 assertFlags(re, true, false, true)
125 107
126 re = RegExp("a", "igii"); 108 assertThrows(function(){ return RegExp("a", "iigi"); })
127 assertFlags(re, true, false, true)
128 109
129 re = RegExp("a", "iigi"); 110 assertThrows(function(){ return RegExp("a", "iiig"); })
130 assertFlags(re, true, false, true)
131 111
132 re = RegExp("a", "iiig"); 112 assertThrows(function(){ return RegExp("a", "miiig"); })
133 assertFlags(re, true, false, true)
134 113
135 re = RegExp("a", "miiig"); 114 // Illegal flags - valid flags late in string.
136 assertFlags(re, true, true, true)
137 115
138 // Illegal flags - flags late in string. 116 assertThrows("/a/arglebargleglopglyf");
139 117
140 re = /a/arglebargleglopglyf; 118 assertThrows("/a/arglebargleglopglif");
141 assertFlags(re, true, false, false)
142 119
143 re = /a/arglebargleglopglif; 120 assertThrows("/a/arglebargleglopglym");
144 assertFlags(re, true, false, true)
145 121
146 re = /a/arglebargleglopglym; 122 assertThrows("/a/arglebargleglopglim");
147 assertFlags(re, true, true, false)
148
149 re = /a/arglebargleglopglim;
150 assertFlags(re, true, true, true)
151 123
152 // Case of flags still matters. 124 // Case of flags still matters.
153 125
154 re = /a/gmi; 126 var re = /a/gmi;
155 assertFlags(re, true, true, true) 127 assertFlags(re, true, true, true)
156 128
157 re = /a/Gmi; 129 assertThrows("/a/Gmi");
158 assertFlags(re, false, true, true)
159 130
160 re = /a/gMi; 131 assertThrows("/a/gMi");
161 assertFlags(re, true, false, true)
162 132
163 re = /a/gmI; 133 assertThrows("/a/gmI");
164 assertFlags(re, true, true, false)
165 134
166 re = /a/GMi; 135 assertThrows("/a/GMi");
167 assertFlags(re, false, false, true)
168 136
169 re = /a/GmI; 137 assertThrows("/a/GmI");
170 assertFlags(re, false, true, false)
171 138
172 re = /a/gMI; 139 assertThrows("/a/gMI");
173 assertFlags(re, true, false, false)
174 140
175 re = /a/GMI; 141 assertThrows("/a/GMI");
176 assertFlags(re, false, false, false) 142
143 // Unicode escape sequences are not interpreted.
144
145 assertThrows("/a/\\u0067");
146 assertThrows("/a/\\u0069");
147 assertThrows("/a/\\u006d");
148 assertThrows("/a/\\u006D");
OLDNEW
« no previous file with comments | « src/regexp.js ('k') | test/mjsunit/regress/regress-87.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698