Repository navigation
Split "]]>" across CDATA sections when writing - #401
Open
Asimmirzac wants to merge 1 commit into
Open
Asimmirzac wants to merge 1 commit into
Asimmirzac wants to merge 1 commit into
Conversation
A CDATA section ends at the first "]]>", so a REXML::CData whose value contains "]]>" was written as malformed XML: REXML::Document.new on the output keeps only the part before "]]>" as CDATA and turns the rest into text, and other parsers (expat, libxml2) reject it. Write each "]]>" as "]]]]><![CDATA[>" instead, ending the section after "]]" and opening a new one that starts with ">". Parsers read the sections back as the original text. The CData value itself is not changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
A CDATA section ends at the first
]]>, but REXML writes aREXML::CDatavalue as is, so a value containing]]>produces malformed XML and the content is lost on the next parse:Python's expat rejects the same output with "not well-formed (invalid token)".
This PR writes each
]]>as]]]]><![CDATA[>: the section is closed after]]and a new one starts with>, which is the usual way to put]]>in CDATA. With the change the example above writes<script><![CDATA[if (a[b[0]]]]><![CDATA[>1) {}]]></script>, REXML and expat both read it back asif (a[b[0]]>1) {}, and the CData value itself is not modified. The splitting is in a smallCData.escape_stophelper used byFormatters::Default#write_cdata(so also Pretty and Transitive) and by the deprecatedCData#write.Tests were added in
test/formatter/test_default.rbandtest/formatter/test_pretty.rb(4 of the 5 fail without the change).ruby test/run.rbpasses (886 tests, 0 failures) with Ruby 3.2, also withRUBYOPT=--enable-frozen-string-literal.Prepared with AI assistance (Claude Code).
🤖 Generated with Claude Code