Bug 950105 - Escape reserved characters when converting a WBXML document to XML. r=vicamo, r=chucklee

This commit is contained in:
Gabriele Svelto 2013-12-18 17:19:42 +01:00
Родитель d2d7c07e2e
Коммит b00a679c4b
2 изменённых файлов: 63 добавлений и 3 удалений

Просмотреть файл

@ -93,6 +93,35 @@ this.WbxmlEnd = {
},
};
/**
* Escape XML reserved characters &, <, >, " and ' which may appear in the
* WBXML-encoded strings in their original form.
*
* @param str
* A string with potentially unescaped characters
*
* @return A string with the &, <, >, " and ' characters turned into XML
* character entitites
*
* @see WAP-192-WBXML-20010725-A, clause 6.1
*/
this.escapeReservedCharacters = function escape_reserved_characters(str) {
let dst = "";
for (var i = 0; i < str.length; i++) {
switch (str[i]) {
case '&' : dst += "&amp;" ; break;
case '<' : dst += "&lt;" ; break;
case '>' : dst += "&gt;" ; break;
case '"' : dst += "&quot;"; break;
case '\'': dst += "&apos;"; break;
default : dst += str[i];
}
}
return dst;
}
/**
* Handle string table in WBXML message.
*
@ -118,7 +147,9 @@ this.readStringTable = function decode_wbxml_read_string_table(start, stringTabl
this.WbxmlStringTable = {
decode: function decode_wbxml_string_table(data, decodeInfo) {
let start = WSP.Octet.decode(data);
return readStringTable(start, decodeInfo.stringTable, decodeInfo.charset);
let str = readStringTable(start, decodeInfo.stringTable, decodeInfo.charset);
return escapeReservedCharacters(str);
}
};
@ -142,7 +173,9 @@ this.WbxmlInlineString = {
charCode = WSP.Octet.decode(data);
}
return WSP.PduHelper.decodeStringContent(stringData, decodeInfo.charset);
let str = WSP.PduHelper.decodeStringContent(stringData, decodeInfo.charset);
return escapeReservedCharacters(str);
},
};

Просмотреть файл

@ -110,6 +110,33 @@ add_test(function test_si_parse_wbxml_with_href() {
run_next_test();
});
/**
* SI compressed by WBXML with href attribute containing reserved XML character
*/
add_test(function test_si_parse_wbxml_with_href_reserved_char() {
let msg = {};
let contentType = "";
let data = {};
contentType = "application/vnd.wap.sic";
data.array = new Uint8Array([
0x02, 0x05, 0x6A, 0x00, 0x45, 0xC6, 0x0D, 0x03,
0x6F, 0x72, 0x65, 0x69, 0x6C, 0x6C, 0x79, 0x00,
0x85, 0x03, 0x66, 0x6F, 0x6F, 0x26, 0x62, 0x61,
0x72, 0x00, 0x01, 0x03, 0x43, 0x68, 0x65, 0x63,
0x6B, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x77,
0x65, 0x62, 0x73, 0x69, 0x74, 0x65, 0x00, 0x01,
0x01
]);
data.offset = 0;
let result = "<si><indication href=\"http://www.oreilly.com/foo&amp;bar\">" +
"Check this website</indication></si>";
let msg = SI.PduHelper.parse(data, contentType);
do_check_eq(msg.content, result);
run_next_test();
});
/**
* SI compressed by WBXML with href and date attribute
*/
@ -170,4 +197,4 @@ add_test(function test_si_parse_wbxml_with_attr_string_table() {
do_check_eq(msg.content, result);
run_next_test();
});
});