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

Side by Side Diff: src/uri.js

Issue 8118004: Fix issue 1415 - allow surrogate pair codes in decodeURIComponent. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 2 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 | « no previous file | test/mjsunit/regress/regress-1415.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 var value; 104 var value;
105 var o0 = octets[0]; 105 var o0 = octets[0];
106 if (o0 < 0x80) { 106 if (o0 < 0x80) {
107 value = o0; 107 value = o0;
108 } else if (o0 < 0xc2) { 108 } else if (o0 < 0xc2) {
109 throw new $URIError("URI malformed"); 109 throw new $URIError("URI malformed");
110 } else { 110 } else {
111 var o1 = octets[1]; 111 var o1 = octets[1];
112 if (o0 < 0xe0) { 112 if (o0 < 0xe0) {
113 var a = o0 & 0x1f; 113 var a = o0 & 0x1f;
114 if ((o1 < 0x80) || (o1 > 0xbf)) 114 if ((o1 < 0x80) || (o1 > 0xbf)) {
115 throw new $URIError("URI malformed"); 115 throw new $URIError("URI malformed");
116 }
116 var b = o1 & 0x3f; 117 var b = o1 & 0x3f;
117 value = (a << 6) + b; 118 value = (a << 6) + b;
118 if (value < 0x80 || value > 0x7ff) 119 if (value < 0x80 || value > 0x7ff) {
119 throw new $URIError("URI malformed"); 120 throw new $URIError("URI malformed");
121 }
120 } else { 122 } else {
121 var o2 = octets[2]; 123 var o2 = octets[2];
122 if (o0 < 0xf0) { 124 if (o0 < 0xf0) {
123 var a = o0 & 0x0f; 125 var a = o0 & 0x0f;
124 if ((o1 < 0x80) || (o1 > 0xbf)) 126 if ((o1 < 0x80) || (o1 > 0xbf)) {
125 throw new $URIError("URI malformed"); 127 throw new $URIError("URI malformed");
128 }
126 var b = o1 & 0x3f; 129 var b = o1 & 0x3f;
127 if ((o2 < 0x80) || (o2 > 0xbf)) 130 if ((o2 < 0x80) || (o2 > 0xbf)) {
128 throw new $URIError("URI malformed"); 131 throw new $URIError("URI malformed");
132 }
129 var c = o2 & 0x3f; 133 var c = o2 & 0x3f;
130 value = (a << 12) + (b << 6) + c; 134 value = (a << 12) + (b << 6) + c;
131 if ((value < 0x800) || (value > 0xffff)) 135 if ((value < 0x800) || (value > 0xffff)) {
132 throw new $URIError("URI malformed"); 136 throw new $URIError("URI malformed");
137 }
133 } else { 138 } else {
134 var o3 = octets[3]; 139 var o3 = octets[3];
135 if (o0 < 0xf8) { 140 if (o0 < 0xf8) {
136 var a = (o0 & 0x07); 141 var a = (o0 & 0x07);
137 if ((o1 < 0x80) || (o1 > 0xbf)) 142 if ((o1 < 0x80) || (o1 > 0xbf)) {
138 throw new $URIError("URI malformed"); 143 throw new $URIError("URI malformed");
144 }
139 var b = (o1 & 0x3f); 145 var b = (o1 & 0x3f);
140 if ((o2 < 0x80) || (o2 > 0xbf)) 146 if ((o2 < 0x80) || (o2 > 0xbf)) {
141 throw new $URIError("URI malformed"); 147 throw new $URIError("URI malformed");
148 }
142 var c = (o2 & 0x3f); 149 var c = (o2 & 0x3f);
143 if ((o3 < 0x80) || (o3 > 0xbf)) 150 if ((o3 < 0x80) || (o3 > 0xbf)) {
144 throw new $URIError("URI malformed"); 151 throw new $URIError("URI malformed");
152 }
145 var d = (o3 & 0x3f); 153 var d = (o3 & 0x3f);
146 value = (a << 18) + (b << 12) + (c << 6) + d; 154 value = (a << 18) + (b << 12) + (c << 6) + d;
147 if ((value < 0x10000) || (value > 0x10ffff)) 155 if ((value < 0x10000) || (value > 0x10ffff)) {
148 throw new $URIError("URI malformed"); 156 throw new $URIError("URI malformed");
157 }
149 } else { 158 } else {
150 throw new $URIError("URI malformed"); 159 throw new $URIError("URI malformed");
151 } 160 }
152 } 161 }
153 } 162 }
154 } 163 }
164 if (0xD800 <= value && value <= 0xDFFF) {
165 throw new $URIError("URI malformed");
166 }
155 if (value < 0x10000) { 167 if (value < 0x10000) {
156 result[index++] = value; 168 result[index++] = value;
157 return index; 169 return index;
158 } else { 170 } else {
159 result[index++] = (value >> 10) + 0xd7c0; 171 result[index++] = (value >> 10) + 0xd7c0;
160 result[index++] = (value & 0x3ff) + 0xdc00; 172 result[index++] = (value & 0x3ff) + 0xdc00;
161 return index; 173 return index;
162 } 174 }
163 } 175 }
164 176
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 var cc = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt(++k)); 219 var cc = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt(++k));
208 if (cc >> 7) { 220 if (cc >> 7) {
209 var n = 0; 221 var n = 0;
210 while (((cc << ++n) & 0x80) != 0) ; 222 while (((cc << ++n) & 0x80) != 0) ;
211 if (n == 1 || n > 4) throw new $URIError("URI malformed"); 223 if (n == 1 || n > 4) throw new $URIError("URI malformed");
212 var octets = new $Array(n); 224 var octets = new $Array(n);
213 octets[0] = cc; 225 octets[0] = cc;
214 if (k + 3 * (n - 1) >= uriLength) throw new $URIError("URI malformed"); 226 if (k + 3 * (n - 1) >= uriLength) throw new $URIError("URI malformed");
215 for (var i = 1; i < n; i++) { 227 for (var i = 1; i < n; i++) {
216 if (uri.charAt(++k) != '%') throw new $URIError("URI malformed"); 228 if (uri.charAt(++k) != '%') throw new $URIError("URI malformed");
217 octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt( ++k)); 229 octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k),
230 uri.charCodeAt(++k));
218 } 231 }
219 index = URIDecodeOctets(octets, result, index); 232 index = URIDecodeOctets(octets, result, index);
220 } else { 233 } else {
221 if (reserved(cc)) { 234 if (reserved(cc)) {
222 result[index++] = 37; // Char code of '%'. 235 result[index++] = 37; // Char code of '%'.
223 result[index++] = uri.charCodeAt(k - 1); 236 result[index++] = uri.charCodeAt(k - 1);
224 result[index++] = uri.charCodeAt(k); 237 result[index++] = uri.charCodeAt(k);
225 } else { 238 } else {
226 result[index++] = cc; 239 result[index++] = cc;
227 } 240 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 cc = cc >>> 4; 372 cc = cc >>> 4;
360 } 373 }
361 return r; 374 return r;
362 } 375 }
363 376
364 377
365 // Returns true if all digits in string s are valid hex numbers 378 // Returns true if all digits in string s are valid hex numbers
366 function IsValidHex(s) { 379 function IsValidHex(s) {
367 for (var i = 0; i < s.length; ++i) { 380 for (var i = 0; i < s.length; ++i) {
368 var cc = s.charCodeAt(i); 381 var cc = s.charCodeAt(i);
369 if ((48 <= cc && cc <= 57) || (65 <= cc && cc <= 70) || (97 <= cc && cc <= 1 02)) { 382 if ((48 <= cc && cc <= 57) ||
383 (65 <= cc && cc <= 70) ||
384 (97 <= cc && cc <= 102)) {
370 // '0'..'9', 'A'..'F' and 'a' .. 'f'. 385 // '0'..'9', 'A'..'F' and 'a' .. 'f'.
371 } else { 386 } else {
372 return false; 387 return false;
373 } 388 }
374 } 389 }
375 return true; 390 return true;
376 } 391 }
377 392
378 393
379 // ECMA-262 - B.2.1. 394 // ECMA-262 - B.2.1.
(...skipping 20 matching lines...) Expand all
400 "escape", URIEscape, 415 "escape", URIEscape,
401 "unescape", URIUnescape, 416 "unescape", URIUnescape,
402 "decodeURI", URIDecode, 417 "decodeURI", URIDecode,
403 "decodeURIComponent", URIDecodeComponent, 418 "decodeURIComponent", URIDecodeComponent,
404 "encodeURI", URIEncode, 419 "encodeURI", URIEncode,
405 "encodeURIComponent", URIEncodeComponent 420 "encodeURIComponent", URIEncodeComponent
406 )); 421 ));
407 } 422 }
408 423
409 SetUpUri(); 424 SetUpUri();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-1415.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698