Repository navigation
fix: end processing instruction at first ?> (#924) - #925
Open
anubhavlal07 wants to merge 1 commit into
Open
anubhavlal07 wants to merge 1 commit into
anubhavlal07 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose / Goal
Fixes #924.
A quote inside a processing instruction makes the parser skip past the real
?>. In<r><?note don't forget?><a>1</a><b>it's</b><?end?><c>3</c></r>,a,band?endare dropped. If there is no later matching quote, the parser throwsPi Tag is not closed.Root cause: the PI branch in
OrderedObjParser.jscallsreadTagExp(xmlData, i, false, "?>"), which callstagExpWithClosingIndex. That function treats every'or"as the start of an attribute value and jumps to the next matching quote. PI content is free text, and XML 1.0 production [16] ends a PI at the first?>.Fix:
tagExpWithClosingIndexgets askipQuotesparameter (defaulttrue).readTagExppassesclosingChar !== "?>", so in PIs it does not skip quoted values or replace tabs. Tabs inside quoted PI pseudo-attribute values stay as they are. PI pseudo-attributes such as<?xml version="1.0"?>andxml-stylesheetare still parsed bybuildAttributesMapon the extracted expression. Its regex already splits on any whitespace. Normal tags behave exactly as before.Tests added to
spec/pi_spec.js:?>even inside a quoted value, which matches the validator's existing expectationThe first four fail on master and pass with this change. Full suite: 348 specs, 0 failures.
Benchmark (
node benchmark/XmlParser.mjs,spec/assets/ptest.xml). Runs on this machine vary a lot between identical runs, but there is no regression. The change only touches PI scanning.Type