fix!: preserve DOCTYPE internal subset #498
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
Thx, I will have a closer look over the weekend. |
This reverts commit 1966113.
This comment was marked as outdated.
This comment was marked as outdated.
and document it, update snapshots
|
The regular expressions no longer have a I managed to split the methods again, so they have a managable/testable amount of complexity. The rino example is currently failing, so I have to fix that. The only other thing missing is to add some unit tests for those new methods and for the new error messages, before the PR can be landed. |
|
Rhino doesn't seem to support named groups, which we are now using to get understandable results for ExternalIDs... But I will risk having to change the regular expression and code to make it compatible in a later PR, once it's merged and published, just to see if anybody complains. |
|
@shunkica From my perspective I would land this. Let me know whether you agree or disagree :) Great endurance on this contribution, and I'm looking forward to the next one :) |
|
@karfau I agree. Let's proceed with merging, and we'll tackle any issues that arise in subsequent updates. |
|
landed, I will be able to make a new beta release on the |
|
released as 0.9.0-beta.9 under the |
which is a regression compared to 0.8.x, most likely introduced as part of #498 - add check to `parseDoctypeCommentOrCData` - drop redundant and broken `Element.appendChild` implementation - `hasInsertableNodeType` now checks for `CharacterData` nodes instead of only text nodes - align ParseError and DOMException in how they are extending Error - wrap `DOMException`s in `ParseError` in sax parser - move custom errors to own module - and allow current and modern constructor arguments for DOMException
Per XML spec §2.6, PI data extends to immediately before '?>'. Trailing whitespace inside the PI boundary is content, not separator. Remove \s* before $ in parseInstruction regex so it is no longer stripped. Addresses the trailing-whitespace sub-issue from xmldom#42, backporting xmldom#498 behaviour to the 0.8.x line.
**Target branch**: `release-0.8.x` ### What Remove `\s*` from the `parseInstruction` regex in `lib/sax.js` so that trailing whitespace inside a processing instruction is preserved instead of silently stripped. ### Why Per [XML spec §2.6](https://www.w3.org/TR/xml/#sec-pi), PI data is everything between the mandatory separator whitespace after the target and the closing `?>`. Trailing whitespace inside the PI boundary is content — there is no rule to strip it. Conforming parsers (sax-js, libexpat) preserve it. This was already fixed on `master`/`0.9.x` as a side-effect of the large DOCTYPE rewrite in PR #498 (22k lines). This PR is the minimal, non-breaking backport for the maintained `0.8.x` line. ### How `parseInstruction` builds a substring that already excludes `?>`, so `$` anchors immediately before it. The `\s*` before `$` was greedily consuming any trailing whitespace from PI data before passing it to `domBuilder.processingInstruction`. Removing it — while keeping `*?` on the data group to minimise diff — is the complete fix. ```js // before source.substring(start, end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/) // after source.substring(start, end).match(/^<\?(\S*)\s*([\s\S]*?)$/) ``` Five existing snapshots in `test/xmltest/__snapshots__/not-wf.test.js.snap` were updated: they captured the old buggy behaviour (trailing space stripped from XML-declaration-like PIs in the not-well-formed corpus). The updated snapshots reflect the now-correct output. ### Scope Addresses the trailing-whitespace sub-issue from #42, backporting #498 behaviour to 0.8.x.
Add support for parsing the internal subset of a DOCTYPE and saving it as a string in
DocumentType.internalSubset.BREAKING CHANGE: Many documents that were previously accepted by xmldom, esecially non well-formed ones are no longer accepted. Some issues that were formerly reported as
errors are now afatalError.fixes #117, #497
Spec: XML DOM L2 Core