From 4544ebf38a3267ef09244af7abc6f49674398ddc Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Tue, 18 May 2021 10:22:12 +0200 Subject: [PATCH] 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. --- src/core/xml_parser.js | 1 + test/unit/xml_spec.js | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/core/xml_parser.js b/src/core/xml_parser.js index bf053f1567267..be0877b477e62 100644 --- a/src/core/xml_parser.js +++ b/src/core/xml_parser.js @@ -145,6 +145,7 @@ class XMLParserBase { pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && + s[pos] !== "?" && s[pos] !== "/" ) { ++pos; diff --git a/test/unit/xml_spec.js b/test/unit/xml_spec.js index 1b653fa84ed81..eb2b920bdaa93 100644 --- a/test/unit/xml_spec.js +++ b/test/unit/xml_spec.js @@ -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 = ` + + + + + `; + 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", ""], + ]); + }); });