Repository navigation
Conversation
validateAmpersand only accepted \w characters, so a valid reference such as &foo-bar; made validate() (and parse(xml, true)) fail with InvalidChar even though the parser itself resolves it. Accept any XML NameChar instead; the 20 character limit is unchanged.
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
XMLValidator.validate()rejects well-formed documents that contain an entity reference whose name has-or.in it, soparser.parse(xml, true)(validate, then parse) throws on input the parser itself handles fine.Input
Expected output
Actual output (before this change)
Cause:
validateAmpersandinsrc/validator.jsonly accepted\wcharacters in an entity name. Per the XML spec an entity name is aName, which allows-,.,:and non-ASCII letters after the first character, andDocTypeReaderalready accepts such names.Change:
validateAmpersandnow accepts any XMLNameChar(newisNameCharhelper insrc/util.js, built from the samenameCharset thatisNamealready uses). The existing 20 character limit and the first-character leniency are unchanged, so every input accepted before is still accepted.Tests: added a spec to
spec/validator_spec.js(names with-,.,:, a non-ASCII letter, the DOCTYPE example above, and negative cases for a space,+, and a missing;). It fails before the change;npm test(333 specs, 0 failures) andnpm run test-typespass.Perf (
XMLValidator.validateon a ~270 KB document with many&/</{references, median of 5 runs of 50): 2.42 ms before, 2.10 ms after. I did not runbenchmark/XmlParser.mjs, which needs its own dependency install.Notes: changelog, version and bundles are left to maintainers per the contributing guide.
npm run lintalready reports errors on master (and itsbenchmark/**/*.jsglob matches no files); the one new report from this change is the sameno-misleading-character-classthatsrc/util.jsalready triggers fornameStartChar.Type