FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: full Unicode support in xml (#7428) · NativeScript/NativeScript@b8659e6 · GitHub

Commit b8659e6

Browse files
authored andcommitted
fix: full Unicode support in xml (#7428)
1 parent 250eb31 commit b8659e6

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

‎tests/app/xml-parser-tests/xml-parser-tests.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,32 @@ export var test_XmlParser_EntityReferencesInAttributeValuesAreDecoded = function
5454
TKUnit.assert(data === "<>\"&'", "Expected result: <>\"&'; Actual result: " + data + ";");
5555
};
5656

57+
export var test_XmlParser_UnicodeEntitiesAreDecoded = function () {
58+
var data;
59+
var xmlParser = new xmlModule.XmlParser(function (event: xmlModule.ParserEvent) {
60+
switch (event.eventType) {
61+
case xmlModule.ParserEventType.Text:
62+
data = event.data;
63+
break;
64+
}
65+
});
66+
xmlParser.parse("<element>&#x1f923;&#x2713;</element>");
67+
TKUnit.assert(data === "\uD83E\uDD23\u2713", "Expected result: \uD83E\uDD23\u2713; Actual result: " + data + ";");
68+
};
69+
70+
export var test_XmlParser_UnicodeEntitiesInAttributeValuesAreDecoded = function () {
71+
var data;
72+
var xmlParser = new xmlModule.XmlParser(function (event: xmlModule.ParserEvent) {
73+
switch (event.eventType) {
74+
case xmlModule.ParserEventType.StartElement:
75+
data = event.attributes["text"];
76+
break;
77+
}
78+
});
79+
xmlParser.parse("<Label text=\"&#x1f923;&#x2713;\"/>");
80+
TKUnit.assert(data === "\uD83E\uDD23\u2713", "Expected result: \uD83E\uDD23\u2713; Actual result: " + data + ";");
81+
};
82+
5783
export var test_XmlParser_OnErrorIsCalledWhenAnErrorOccurs = function () {
5884
var e;
5985
var xmlParser = new xmlModule.XmlParser(

‎tns-core-modules/js-libs/easysax/easysax.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ function rpEntities(s, d, x, z) {
188188
};
189189

190190
if (d) {
191-
return String.fromCharCode(d);
191+
return String.fromCodePoint(d);
192192
};
193193

194-
return String.fromCharCode(parseInt(x, 16));
194+
return String.fromCodePoint(parseInt(x, 16));
195195
};
196196

197197
function unEntities(s, i) {

‎tns-core-modules/xml/xml.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,17 @@ function _HandleAmpEntities(found: string, decimalValue: string, hexValue: strin
100100
}
101101
const res = _ampCodes.get(wordValue);
102102
if (res) {
103-
return String.fromCharCode(res);
103+
return String.fromCodePoint(res);
104104
}
105105

106106
// Invalid word; so we just return it
107107
return found;
108108
}
109109
if (decimalValue) {
110-
return String.fromCharCode(parseInt(decimalValue, 10));
110+
return String.fromCodePoint(parseInt(decimalValue, 10));
111111
}
112112

113-
return String.fromCharCode(parseInt(hexValue, 16));
113+
return String.fromCodePoint(parseInt(hexValue, 16));
114114
}
115115

116116
export class XmlParser implements definition.XmlParser {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL