michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * michael@0: * Date: 22 Aug 2009 michael@0: * SUMMARY: Utf8ToOneUcs4Char in jsstr.cpp ,overlong UTF-8 seqence detection problem michael@0: * See http://bugzilla.mozilla.org/show_bug.cgi?id=511859 michael@0: * michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = 511859; michael@0: var summary = 'Utf8ToOneUcs4Char in jsstr.cpp ,overlong UTF-8 seqence detection problem'; michael@0: var status = ''; michael@0: var statusitems = []; michael@0: var actual = ''; michael@0: var actualvalues = []; michael@0: var expect = ''; michael@0: var expectedvalues = []; michael@0: var arg; michael@0: /* michael@0: * The patch for http://bugzilla.mozilla.org/show_bug.cgi?id=511859 michael@0: * defined this value to be the result of an overlong UTF-8 sequence - michael@0: */ michael@0: michael@0: var EX="(Exception thrown)"; michael@0: michael@0: function getActual(s) michael@0: { michael@0: try { michael@0: return decodeURI(s); michael@0: } catch (e) { michael@0: return EX; michael@0: } michael@0: } michael@0: michael@0: //Phase1: overlong sequences michael@0: expect = EX; michael@0: arg = "%C1%BF"; michael@0: status = "Overlong 2byte U+7f :" + arg; michael@0: actual = getActual(arg); michael@0: addThis(); michael@0: michael@0: arg = "%E0%9F%BF"; michael@0: status = "Overlong 3byte U+7ff :" + arg; michael@0: actual = getActual(arg); michael@0: addThis(); michael@0: michael@0: arg = "%F0%88%80%80"; michael@0: status = "Overlong 4byte U+8000 :" + arg; michael@0: actual = getActual(arg); michael@0: addThis(); michael@0: michael@0: arg = "%F0%8F%BF%BF"; michael@0: status = "Overlong 4byte U+ffff :" + arg; michael@0: actual = getActual(arg); michael@0: addThis(); michael@0: michael@0: arg = "%F0%80%C0%80%80"; michael@0: status = "Overlong 5byte U+20000 :" + arg; michael@0: actual = getActual(arg); michael@0: addThis(); michael@0: michael@0: arg = "%F8%84%8F%BF%BF"; michael@0: status = "Overlong 5byte U+10FFFF :" + arg; michael@0: actual = getActual(arg); michael@0: addThis(); michael@0: michael@0: arg = "%FC%80%84%8F%BF%BF"; michael@0: status = "Overlong 6byte U+10FFFF :" + arg; michael@0: actual = getActual(arg); michael@0: addThis(); michael@0: michael@0: //Phase 2:Out of Unicode range michael@0: arg = "%F4%90%80%80%80"; michael@0: status = "4byte 0x110000 :" + arg; michael@0: actual = getActual(arg); michael@0: addThis(); michael@0: arg = "%F8%84%90%80%80"; michael@0: status = "5byte 0x110000 :" + arg; michael@0: actual = getActual(arg); michael@0: addThis(); michael@0: michael@0: arg = "%FC%80%84%90%80%80"; michael@0: status = "6byte 0x110000 :" + arg; michael@0: actual = getActual(arg); michael@0: addThis(); michael@0: michael@0: //Phase 3:Valid sequences must be decoded correctly michael@0: arg = "%7F"; michael@0: status = "valid sequence U+7F :" + arg; michael@0: actual = getActual("%7F"); michael@0: expect = "\x7f"; michael@0: addThis(); michael@0: michael@0: arg = "%C2%80"; michael@0: status = "valid sequence U+80 :" + arg; michael@0: actual = getActual(arg); michael@0: expect = "\x80"; michael@0: addThis(); michael@0: michael@0: arg = "%E0%A0%80"; michael@0: status = "valid sequence U+800 :" + arg; michael@0: actual = getActual("%E0%A0%80"); michael@0: expect = "\u0800"; michael@0: addThis(); michael@0: michael@0: arg = "%F0%90%80%80" michael@0: status = "valid sequence U+10000 :" + arg; michael@0: actual = getActual(arg); michael@0: expect = "\uD800\uDC00"; michael@0: addThis(); michael@0: michael@0: arg = "%F4%8F%BF%BF"; michael@0: status = "valid sequence U+10FFFF :" + arg; michael@0: actual = getActual(arg); michael@0: expect = "\uDBFF\uDFFF"; michael@0: addThis(); michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: michael@0: michael@0: function addThis() michael@0: { michael@0: statusitems[UBound] = status; michael@0: actualvalues[UBound] = actual; michael@0: expectedvalues[UBound] = expect; michael@0: UBound++; michael@0: } michael@0: michael@0: michael@0: function test() michael@0: { michael@0: enterFunc('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus(summary); michael@0: michael@0: for (var i=0; i