зеркало из https://github.com/mozilla/gecko-dev.git
Bug 950105 - Escape reserved characters when converting a WBXML document to XML. r=vicamo, r=chucklee
This commit is contained in:
Родитель
d2d7c07e2e
Коммит
b00a679c4b
|
@ -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 += "&" ; break;
|
||||
case '<' : dst += "<" ; break;
|
||||
case '>' : dst += ">" ; break;
|
||||
case '"' : dst += """; break;
|
||||
case '\'': dst += "'"; 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&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
|
||||
*/
|
||||
|
|
Загрузка…
Ссылка в новой задаче