Skip to content

Inconsistent types when parsing empty tags #97

@lukasbischof

Description

@lukasbischof

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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions