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

Inconsistent types when parsing empty tags #97

Open
lukasbischof opened this issue Sep 28, 2022 · 2 comments · May be fixed by #98
Open

Inconsistent types when parsing empty tags #97

lukasbischof opened this issue Sep 28, 2022 · 2 comments · May be fixed by #98

Comments

@lukasbischof
Copy link

When parsing an empty tag, the result varies depending on the attributes the element has:

Nori.new.parse('<foo />')
#=> {"foo"=>nil}

Nori.new.parse('<foo bar />')
#=> {}

Nori.new.parse('<foo bar="baz"/>')
#=> {"foo"=>{"@bar"=>"baz"}}

Nori.new.parse('<foo bar="baz">Content</foo>')
#=> {"foo"=>"Content"}

It would be handy if there was an option to configure that the parsed response stays consistent (like for string values), even if some information may be lost (e.g. always returning nil, even if there were attributes)

Maybe something like:

Nori.new(ignore_empty_attributes: true).parse('<foo bar />')
#=> {"foo"=>nil}
@pcai
Copy link
Member

pcai commented Sep 29, 2022

Thanks for the suggestion. This is less than 100% intuitive and I will update the README with some of these examples so people are not caught off guard.

If you're open to working this I can review the PR. Otherwise it may have to wait until we get through some more housekeeping before I attempt this myself.

@lukasbischof
Copy link
Author

Ok, thanks for the fast response. I think then I'll try to make a PR soonish

@lukasbischof lukasbischof linked a pull request Oct 14, 2022 that will close this issue
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