Index: src/uri.js |
diff --git a/src/uri.js b/src/uri.js |
index c910d756b4c4cdc96336ba49cf0ea25bc3611fb6..1656664a3d8e56399cfb744600bd4be8e33e6aaf 100644 |
--- a/src/uri.js |
+++ b/src/uri.js |
@@ -111,47 +111,59 @@ function URIDecodeOctets(octets, result, index) { |
var o1 = octets[1]; |
if (o0 < 0xe0) { |
var a = o0 & 0x1f; |
- if ((o1 < 0x80) || (o1 > 0xbf)) |
+ if ((o1 < 0x80) || (o1 > 0xbf)) { |
throw new $URIError("URI malformed"); |
+ } |
var b = o1 & 0x3f; |
value = (a << 6) + b; |
- if (value < 0x80 || value > 0x7ff) |
+ 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)) |
+ if ((o1 < 0x80) || (o1 > 0xbf)) { |
throw new $URIError("URI malformed"); |
+ } |
var b = o1 & 0x3f; |
- if ((o2 < 0x80) || (o2 > 0xbf)) |
+ 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)) |
+ 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)) |
+ if ((o1 < 0x80) || (o1 > 0xbf)) { |
throw new $URIError("URI malformed"); |
+ } |
var b = (o1 & 0x3f); |
- if ((o2 < 0x80) || (o2 > 0xbf)) |
+ if ((o2 < 0x80) || (o2 > 0xbf)) { |
throw new $URIError("URI malformed"); |
+ } |
var c = (o2 & 0x3f); |
- if ((o3 < 0x80) || (o3 > 0xbf)) |
+ 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)) |
+ if ((value < 0x10000) || (value > 0x10ffff)) { |
throw new $URIError("URI malformed"); |
+ } |
} else { |
throw new $URIError("URI malformed"); |
} |
} |
} |
} |
+ if (0xD800 <= value && value <= 0xDFFF) { |
+ throw new $URIError("URI malformed"); |
+ } |
if (value < 0x10000) { |
result[index++] = value; |
return index; |
@@ -214,7 +226,8 @@ function Decode(uri, reserved) { |
if (k + 3 * (n - 1) >= uriLength) throw new $URIError("URI malformed"); |
for (var i = 1; i < n; i++) { |
if (uri.charAt(++k) != '%') throw new $URIError("URI malformed"); |
- octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt(++k)); |
+ octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k), |
+ uri.charCodeAt(++k)); |
} |
index = URIDecodeOctets(octets, result, index); |
} else { |
@@ -366,7 +379,9 @@ function CharCodeToHex4Str(cc) { |
function IsValidHex(s) { |
for (var i = 0; i < s.length; ++i) { |
var cc = s.charCodeAt(i); |
- if ((48 <= cc && cc <= 57) || (65 <= cc && cc <= 70) || (97 <= cc && cc <= 102)) { |
+ if ((48 <= cc && cc <= 57) || |
+ (65 <= cc && cc <= 70) || |
+ (97 <= cc && cc <= 102)) { |
// '0'..'9', 'A'..'F' and 'a' .. 'f'. |
} else { |
return false; |