Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization of ATTLIST is incorrect #233

Closed
OlofKalufs opened this issue Jan 16, 2025 · 2 comments · Fixed by #234
Closed

Serialization of ATTLIST is incorrect #233

OlofKalufs opened this issue Jan 16, 2025 · 2 comments · Fixed by #234

Comments

@OlofKalufs
Copy link
Contributor

When parsing and then serializing an XML document with a DTD internal subset containing an ATTLIST, the "<!ATTLIST" part is missing. See this example:

require 'rexml'

xml_string = %{
<!DOCTYPE elem [
   <!ELEMENT elem EMPTY>
   <!ATTLIST elem attr CDATA #REQUIRED>
]>
<elem attr="value"/>
}

xml_document = REXML::Document.new(xml_string)

puts xml_document.to_s
# Outputs:
# <!DOCTYPE elem [
# <!ELEMENT elem EMPTY>
#  elem attr CDATA #REQUIRED>
# ]><elem attr='value'/>

Tried with REXML 3.4.0 on Ruby 3.3.6

@naitoh
Copy link
Contributor

naitoh commented Jan 16, 2025

Thanks for your report, There seems to be a problem with rexml 3.2.7 and later.
I will investigate.

$ gem install rexml -v 3.2.6
$ ruby -r rexml -e 'puts REXML::Document.new("<!DOCTYPE elem [<!ATTLIST elem attr CDATA #REQUIRED>]>")'
<!DOCTYPE elem [
<!ATTLIST elem attr CDATA #REQUIRED>
]>
$ gem install rexml -v 3.2.7
$ ruby -r rexml -e 'puts REXML::Document.new("<!DOCTYPE elem [<!ATTLIST elem attr CDATA #REQUIRED>]>")'
<!DOCTYPE elem [
 elem attr CDATA #REQUIRED>
]>

@OlofKalufs
Copy link
Contributor Author

Ah, good find! I made a PR for this that you're free to merge if you want

OlofKalufs added a commit to OlofKalufs/rexml that referenced this issue Jan 20, 2025
@naitoh naitoh closed this as completed in 107e273 Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants