Skip to content

Commit

Permalink
bugfix when string ends with escape sequence (#11883)
Browse files Browse the repository at this point in the history
* bugfix when string ends with escape sequence

* add test

* fix php too

* like this?

* argh

---------

Co-authored-by: Simon Krajewski <[email protected]>
  • Loading branch information
ncannasse and Simn authored Dec 16, 2024
1 parent 2bee9f0 commit 5e9ea0b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion std/haxe/xml/Parser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,10 @@ class Parser {
if (parent.nodeType == Element) {
throw new XmlParserException("Unclosed node <" + parent.nodeName + ">", str, p);
}
if (p != start || nsubs == 0) {
if( p != start )
buf.addSub(str, start, p - start);
var str = buf.toString();
if (str.length > 0 || nsubs == 0) {
addChild(Xml.createPCData(buf.toString()));
}
return p;
Expand Down
8 changes: 4 additions & 4 deletions std/php/_std/haxe/xml/Parser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ class Parser {
p += 8;
state = S.DOCTYPE;
start = p + 1;
} else if (str.fastCodeAt(p + 1) != '-'.code || str.fastCodeAt(p + 2) != '-'.code)
throw new XmlParserException("Expected <!--", str, p);
else {
} else if (str.fastCodeAt(p + 1) != '-'.code || str.fastCodeAt(p + 2) != '-'.code) throw new XmlParserException("Expected <!--",
str, p); else {
p += 2;
state = S.COMMENT;
start = p + 1;
Expand Down Expand Up @@ -362,8 +361,9 @@ class Parser {
if (parent.nodeType == Element) {
throw new XmlParserException("Unclosed node <" + parent.nodeName + ">", str, p);
}
if (p != start || nsubs == 0) {
if (p != start)
buf = buf.addSub(str, start, p - start);
if (buf != "" || nsubs == 0) {
addChild(Xml.createPCData(buf));
}
return p;
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/src/unit/issues/Issue11883.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package unit.issues;

import unit.Test;

class Issue11883 extends Test {
function test() {
eq(Xml.parse("<foo>xx</foo> bar&lt;").toString(), "<foo>xx</foo> bar&lt;");
}
}

0 comments on commit 5e9ea0b

Please sign in to comment.