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

[bug] DTD#attributes should not be a hash, it should be an array #2995

Open
flavorjones opened this issue Sep 24, 2023 · 2 comments
Open

[bug] DTD#attributes should not be a hash, it should be an array #2995

flavorjones opened this issue Sep 24, 2023 · 2 comments
Milestone

Comments

@flavorjones
Copy link
Member

Please describe the bug

Since 35cace6 in 2008, DTD#attributes has returned a Hash<String => AttributeDecl> where the key is the attribute name.

This doesn't make any sense, since the attribute name does not need to be unique, for example:

doc = Nokogiri::XML::Document.parse(<<~XML)
  <?xml version="1.0"?>
  <!DOCTYPE staff SYSTEM "foo.dtd" [
     <!ATTLIST br width CDATA "0">
     <!ATTLIST a width CDATA "0">
  ]>
  <root />
XML

doc.internal_subset.attributes
# => {"width"=>#(AttributeDecl:0x43f8 { "<!ATTLIST br width CDATA \"0\">\n" })}

This should probably just be an array, and not a hash. And in that case, DTD should not be Enumerable and we should remove the #each method.

@flavorjones
Copy link
Member Author

Also just a note that AttributeDecl does not support declaring multiple attributes, see https://www.w3.org/TR/xml/#attdecls

@flavorjones flavorjones added this to the v1.17.0 milestone Jan 30, 2024
@flavorjones
Copy link
Member Author

I think the right thing to do here is:

  • write a new method, maybe #attribute_list, to return an Array<AttributeDecl>
  • deprecate #attributes and plan for removal in the next major release
  • deprecate #each and plan for removal in the next major release

Opinions welcome.

@flavorjones flavorjones modified the milestones: v1.17.0, v1.18.0 Dec 8, 2024
@flavorjones flavorjones modified the milestones: v1.18.0, v1.19.0 Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant