diff --git a/src/xmlparser.c b/src/xmlparser.c index fbd892d..b90b23d 100644 --- a/src/xmlparser.c +++ b/src/xmlparser.c @@ -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 ++; @@ -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 { diff --git a/test/documents/xmlescape.xml b/test/documents/xmlescape.xml new file mode 100644 index 0000000..590414a --- /dev/null +++ b/test/documents/xmlescape.xml @@ -0,0 +1 @@ +Vedrøæende russer ??????? \ No newline at end of file diff --git a/test/issue97.rpgle b/test/issue97.rpgle new file mode 100644 index 0000000..37045b9 --- /dev/null +++ b/test/issue97.rpgle @@ -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;