Skip to content

Commit

Permalink
fix issue #97 unicode escapes in XML
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsLiisberg committed Dec 19, 2024
1 parent 69f8f1f commit 38588d9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/xmlparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ static void nox_XmlDecode (PUCHAR out, PUCHAR in , ULONG inlen)
else if (amemiBeginsWith(kwd ,"apos;")){ *(p++) = APOS; in += 6; }
else if (amemiBeginsWith(kwd ,"quot;")){ *(p++) = QUOT; in += 6; }
else if (in[1] == HASH) {
int n = 0;
USHORT n = 0;
int l = 0;
in += 2; // Skip the '&#'
if (*in == 'x' || *in == 'X') { // Hexadecimal representation
in ++;
Expand All @@ -65,20 +66,18 @@ static void nox_XmlDecode (PUCHAR out, PUCHAR in , ULONG inlen)
in ++;
}
} else { // Decimal representation
while (*in >= '0') {
while (*in >= '0' && *in <= '9') {
n = 10 * n + ((*in) - '0');
in ++;
}
}
if (n<=255) {
*(p++) = n;
// Unicode chars ...
} else {
int l = XlateBuf(p , (PUCHAR) &n , 2 , 13488, 1208 );
if (l==0 || *p <= ' ') { // Invalid char or replacement char ..
*p = '.';
}

l = XlateBuf(p , (PUCHAR) &n , 2 , 13488, 1208 );
if (l==0 || *p <= ' ') { // Invalid char or replacement char ..
*p = '.';
p++;
} else {
p += l;
}
in ++;
} else {
Expand Down
1 change: 1 addition & 0 deletions test/documents/xmlescape.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a>Vedr&#248;&#230;ende russer ???????</a>
18 changes: 18 additions & 0 deletions test/issue97.rpgle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
**free
Ctl-Opt BndDir('NOXDB2') dftactgrp(*NO) ACTGRP('QILE' ) main(main);

/include 'headers/noxDb2.rpgle'

dcl-proc main;
dcl-s xml pointer;
dcl-s value varchar(200) ccsid(*utf8);
dcl-s message char(50);

xml = nox_ParseFile('./test/documents/xmlescape.xml');
value = nox_asXmlText(xml);
message = value;
dsply message;

on-exit;
nox_delete(xml);
end-proc;

0 comments on commit 38588d9

Please sign in to comment.