Handle PI with no value in xml parser

- an XML PI contains a target and optionally some content (see https://en.wikipedia.org/wiki/Processing_Instruction)
  - the parser expected to always have some content and so it could lead to wrong parsing.
This commit is contained in:
Calixte Denizet 2021-05-18 10:22:12 +02:00
parent 17e9cfcd2a
commit 4544ebf38a
2 changed files with 26 additions and 1 deletions

View File

@ -145,6 +145,7 @@ class XMLParserBase {
pos < s.length &&
!isWhitespace(s, pos) &&
s[pos] !== ">" &&
s[pos] !== "?" &&
s[pos] !== "/"
) {
++pos;

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
import { SimpleXMLParser, XMLParserBase } from "../../src/core/xml_parser.js";
import { parseXFAPath } from "../../src/core/core_utils.js";
import { SimpleXMLParser } from "../../src/core/xml_parser.js";
describe("XML", function () {
describe("searchNode", function () {
@ -108,4 +108,28 @@ describe("XML", function () {
);
});
});
it("should parse processing instructions", function () {
const xml = `
<a>
<?foo bar?>
<?foo bar oof?>
<?foo?>
</a>`;
const pi = [];
class MyParser extends XMLParserBase {
onPi(name, value) {
pi.push([name, value]);
}
}
new MyParser().parseXml(xml);
expect(pi).toEqual([
["foo", "bar"],
["foo", "bar oof"],
["foo", ""],
]);
});
});