Author: [email protected]
Date: Tue Mar 10 02:08:05 2009
New Revision: 1471
Added:
branches/bleeding_edge/test/mjsunit/regress/regress-244.js
Modified:
branches/bleeding_edge/src/regexp-delay.js
branches/bleeding_edge/src/uri.js
Log:
Implemented invalid UTF8 detection in decodeURI. That is, detection
of invalid utf8 not invalid utf8-detection.
Modified: branches/bleeding_edge/src/regexp-delay.js
==============================================================================
--- branches/bleeding_edge/src/regexp-delay.js (original)
+++ branches/bleeding_edge/src/regexp-delay.js Tue Mar 10 02:08:05 2009
@@ -302,10 +302,6 @@
"compile", CompileRegExp
));
- // The spec says nothing about the length of exec and test, but
- // SpiderMonkey and KJS have length equal to 0.
- %FunctionSetLength($RegExp.prototype.exec, 0);
- %FunctionSetLength($RegExp.prototype.test, 0);
// The length of compile is 1 in SpiderMonkey.
%FunctionSetLength($RegExp.prototype.compile, 1);
Modified: branches/bleeding_edge/src/uri.js
==============================================================================
--- branches/bleeding_edge/src/uri.js (original)
+++ branches/bleeding_edge/src/uri.js Tue Mar 10 02:08:05 2009
@@ -90,27 +90,65 @@
function URIDecodeOctets(octets, result, index) {
- if (octets[3]) {
- var x = (octets[2] >> 4) & 3;
- var y = octets[2] & 0xF;
- var z = octets[3] & 63;
- var v = (((octets[0] & 7) << 2) | ((octets[1] >> 4) & 3)) - 1;
- var w = octets[1] & 0xF;
- result[index++] = 55296 | (v << 6) | (w << 2) | x;
- result[index++] = 56320 | (y << 6) | z;
- return index;
+ var value;
+ var o0 = octets[0];
+ if (o0 < 0x80) {
+ value = o0;
+ } else if (o0 < 0xc2) {
+ throw new $URIError("URI malformed");
+ } else {
+ var o1 = octets[1];
+ if (o0 < 0xe0) {
+ var a = o0 & 0x1f;
+ if ((o1 < 0x80) || (o1 > 0xbf))
+ throw new $URIError("URI malformed");
+ var b = o1 & 0x3f;
+ value = (a << 6) + b;
+ if (value < 0x80 || value > 0x7ff)
+ throw new $URIError("URI malformed");
+ } else {
+ var o2 = octets[2];
+ if (o0 < 0xf0) {
+ var a = o0 & 0x0f;
+ if ((o1 < 0x80) || (o1 > 0xbf))
+ throw new $URIError("URI malformed");
+ var b = o1 & 0x3f;
+ if ((o2 < 0x80) || (o2 > 0xbf))
+ throw new $URIError("URI malformed");
+ var c = o2 & 0x3f;
+ value = (a << 12) + (b << 6) + c;
+ if ((value < 0x800) || (value > 0xffff))
+ throw new $URIError("URI malformed");
+ } else {
+ var o3 = octets[3];
+ if (o0 < 0xf8) {
+ var a = (o0 & 0x07);
+ if ((o1 < 0x80) || (o1 > 0xbf))
+ throw new $URIError("URI malformed");
+ var b = (o1 & 0x3f);
+ if ((o2 < 0x80) || (o2 > 0xbf))
+ throw new $URIError("URI malformed");
+ var c = (o2 & 0x3f);
+ if ((o3 < 0x80) || (o3 > 0xbf))
+ throw new $URIError("URI malformed");
+ var d = (o3 & 0x3f);
+ value = (a << 18) + (b << 12) + (c << 6) + d;
+ if ((value < 0x10000) || (value > 0x10ffff))
+ throw new $URIError("URI malformed");
+ } else {
+ throw new $URIError("URI malformed");
+ }
+ }
+ }
}
- if (octets[2]) {
- var x = octets[0] & 0xF;
- var y = octets[1] & 63;
- var z = octets[2] & 63;
- result[index++] = (x << 12) | (y << 6) | z;
+ if (value < 0x10000) {
+ result[index++] = value;
+ return index;
+ } else {
+ result[index++] = (value >> 10) + 0xd7c0;
+ result[index++] = (value & 0x3ff) + 0xdc00;
return index;
}
- var z = octets[1] & 63;
- var y = octets[0] & 31;
- result[index++] = (y << 6) | z;
- return index;
}
Added: branches/bleeding_edge/test/mjsunit/regress/regress-244.js
==============================================================================
--- (empty file)
+++ branches/bleeding_edge/test/mjsunit/regress/regress-244.js Tue Mar 10
02:08:05 2009
@@ -0,0 +1,67 @@
+// Copyright 2009 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+var kLegalPairs = [
+ [0x00, '%00'],
+ [0x01, '%01'],
+ [0x7f, '%7F'],
+ [0x80, '%C2%80'],
+ [0x81, '%C2%81'],
+ [0x7ff, '%DF%BF'],
+ [0x800, '%E0%A0%80'],
+ [0x801, '%E0%A0%81'],
+ [0xd7ff, '%ED%9F%BF'],
+ [0xffff, '%EF%BF%BF']
+];
+
+var kIllegalEncoded = [
+ '%80', '%BF', '%80%BF', '%80%BF%80', '%C0%22', '%DF',
+ '%EF%BF', '%F7BFBF', '%FE', '%FF', '%FE%FE%FF%FF',
+ '%C0%AF', '%E0%9F%BF', '%F0%8F%BF%BF', '%C0%80',
+ '%E0%80%80'
+];
+
+function run() {
+ for (var i = 0; i < kLegalPairs.length; i++) {
+ var decoded = String.fromCharCode(kLegalPairs[i][0]);
+ var encoded = kLegalPairs[i][1];
+ assertEquals(decodeURI(encoded), decoded);
+ assertEquals(encodeURI(decoded), encoded);
+ }
+ for (var i = 0; i < kIllegalEncoded.length; i++) {
+ var value = kIllegalEncoded[i];
+ var threw = false;
+ try {
+ decodeURI(value);
+ fail(value);
+ } catch (e) {
+ assertInstanceof(e, URIError);
+ }
+ }
+}
+
+run();
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---