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:
parent
17e9cfcd2a
commit
4544ebf38a
@ -145,6 +145,7 @@ class XMLParserBase {
|
|||||||
pos < s.length &&
|
pos < s.length &&
|
||||||
!isWhitespace(s, pos) &&
|
!isWhitespace(s, pos) &&
|
||||||
s[pos] !== ">" &&
|
s[pos] !== ">" &&
|
||||||
|
s[pos] !== "?" &&
|
||||||
s[pos] !== "/"
|
s[pos] !== "/"
|
||||||
) {
|
) {
|
||||||
++pos;
|
++pos;
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { SimpleXMLParser, XMLParserBase } from "../../src/core/xml_parser.js";
|
||||||
import { parseXFAPath } from "../../src/core/core_utils.js";
|
import { parseXFAPath } from "../../src/core/core_utils.js";
|
||||||
import { SimpleXMLParser } from "../../src/core/xml_parser.js";
|
|
||||||
|
|
||||||
describe("XML", function () {
|
describe("XML", function () {
|
||||||
describe("searchNode", 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", ""],
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user