| 1 |
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ |
| 2 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 |
|
| 6 |
/* |
| 7 |
* |
| 8 |
* Date: 22 Aug 2009 |
| 9 |
* SUMMARY: Utf8ToOneUcs4Char in jsstr.cpp ,overlong UTF-8 seqence detection problem |
| 10 |
* See http://bugzilla.mozilla.org/show_bug.cgi?id=511859 |
| 11 |
* |
| 12 |
*/ |
| 13 |
//----------------------------------------------------------------------------- |
| 14 |
var UBound = 0; |
| 15 |
var BUGNUMBER = 511859; |
| 16 |
var summary = 'Utf8ToOneUcs4Char in jsstr.cpp ,overlong UTF-8 seqence detection problem'; |
| 17 |
var status = ''; |
| 18 |
var statusitems = []; |
| 19 |
var actual = ''; |
| 20 |
var actualvalues = []; |
| 21 |
var expect = ''; |
| 22 |
var expectedvalues = []; |
| 23 |
var arg; |
| 24 |
/* |
| 25 |
* The patch for http://bugzilla.mozilla.org/show_bug.cgi?id=511859 |
| 26 |
* defined this value to be the result of an overlong UTF-8 sequence - |
| 27 |
*/ |
| 28 |
|
| 29 |
var EX="(Exception thrown)"; |
| 30 |
|
| 31 |
function getActual(s) |
| 32 |
{ |
| 33 |
try { |
| 34 |
return decodeURI(s); |
| 35 |
} catch (e) { |
| 36 |
return EX; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
//Phase1: overlong sequences |
| 41 |
expect = EX; |
| 42 |
arg = "%C1%BF"; |
| 43 |
status = "Overlong 2byte U+7f :" + arg; |
| 44 |
actual = getActual(arg); |
| 45 |
addThis(); |
| 46 |
|
| 47 |
arg = "%E0%9F%BF"; |
| 48 |
status = "Overlong 3byte U+7ff :" + arg; |
| 49 |
actual = getActual(arg); |
| 50 |
addThis(); |
| 51 |
|
| 52 |
arg = "%F0%88%80%80"; |
| 53 |
status = "Overlong 4byte U+8000 :" + arg; |
| 54 |
actual = getActual(arg); |
| 55 |
addThis(); |
| 56 |
|
| 57 |
arg = "%F0%8F%BF%BF"; |
| 58 |
status = "Overlong 4byte U+ffff :" + arg; |
| 59 |
actual = getActual(arg); |
| 60 |
addThis(); |
| 61 |
|
| 62 |
arg = "%F0%80%C0%80%80"; |
| 63 |
status = "Overlong 5byte U+20000 :" + arg; |
| 64 |
actual = getActual(arg); |
| 65 |
addThis(); |
| 66 |
|
| 67 |
arg = "%F8%84%8F%BF%BF"; |
| 68 |
status = "Overlong 5byte U+10FFFF :" + arg; |
| 69 |
actual = getActual(arg); |
| 70 |
addThis(); |
| 71 |
|
| 72 |
arg = "%FC%80%84%8F%BF%BF"; |
| 73 |
status = "Overlong 6byte U+10FFFF :" + arg; |
| 74 |
actual = getActual(arg); |
| 75 |
addThis(); |
| 76 |
|
| 77 |
//Phase 2:Out of Unicode range |
| 78 |
arg = "%F4%90%80%80%80"; |
| 79 |
status = "4byte 0x110000 :" + arg; |
| 80 |
actual = getActual(arg); |
| 81 |
addThis(); |
| 82 |
arg = "%F8%84%90%80%80"; |
| 83 |
status = "5byte 0x110000 :" + arg; |
| 84 |
actual = getActual(arg); |
| 85 |
addThis(); |
| 86 |
|
| 87 |
arg = "%FC%80%84%90%80%80"; |
| 88 |
status = "6byte 0x110000 :" + arg; |
| 89 |
actual = getActual(arg); |
| 90 |
addThis(); |
| 91 |
|
| 92 |
//Phase 3:Valid sequences must be decoded correctly |
| 93 |
arg = "%7F"; |
| 94 |
status = "valid sequence U+7F :" + arg; |
| 95 |
actual = getActual("%7F"); |
| 96 |
expect = "\x7f"; |
| 97 |
addThis(); |
| 98 |
|
| 99 |
arg = "%C2%80"; |
| 100 |
status = "valid sequence U+80 :" + arg; |
| 101 |
actual = getActual(arg); |
| 102 |
expect = "\x80"; |
| 103 |
addThis(); |
| 104 |
|
| 105 |
arg = "%E0%A0%80"; |
| 106 |
status = "valid sequence U+800 :" + arg; |
| 107 |
actual = getActual("%E0%A0%80"); |
| 108 |
expect = "\u0800"; |
| 109 |
addThis(); |
| 110 |
|
| 111 |
arg = "%F0%90%80%80" |
| 112 |
status = "valid sequence U+10000 :" + arg; |
| 113 |
actual = getActual(arg); |
| 114 |
expect = "\uD800\uDC00"; |
| 115 |
addThis(); |
| 116 |
|
| 117 |
arg = "%F4%8F%BF%BF"; |
| 118 |
status = "valid sequence U+10FFFF :" + arg; |
| 119 |
actual = getActual(arg); |
| 120 |
expect = "\uDBFF\uDFFF"; |
| 121 |
addThis(); |
| 122 |
|
| 123 |
//----------------------------------------------------------------------------- |
| 124 |
test(); |
| 125 |
//----------------------------------------------------------------------------- |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
function addThis() |
| 130 |
{ |
| 131 |
statusitems[UBound] = status; |
| 132 |
actualvalues[UBound] = actual; |
| 133 |
expectedvalues[UBound] = expect; |
| 134 |
UBound++; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
function test() |
| 139 |
{ |
| 140 |
printBugNumber(BUGNUMBER); |
| 141 |
printStatus(summary); |
| 142 |
|
| 143 |
for (var i=0; i<UBound; i++) |
| 144 |
{ |
| 145 |
reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
| 146 |
} |
| 147 |
} |