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

Fix an error when parsing attribute without quotes and value #138

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Earlopain
Copy link

I stumbled across the following html snippet which crashes the parser: <div foo=>bar</div>. The interpreted html from browsers (both chrome and firefox) is <div foo="">bar</div> so the generated ast with the fix seems to make sense to me.

Error trace

/home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/parser-3.3.4.2/lib/parser/source/range.rb:39:in `initialize': Parser::Source::Range: end_pos must not be less than begin_pos (ArgumentError)

          raise ArgumentError, 'Parser::Source::Range: end_pos must not be less than begin_pos'
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/tokenizer/location.rb:23:in `initialize'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:214:in `new'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:214:in `build_location'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:206:in `build_node'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:177:in `build_attribute_node'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:151:in `build_tag_attributes_node'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:133:in `build_tag_node'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:79:in `build_document_node'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:49:in `ast'

```
/home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/parser-3.3.4.2/lib/parser/source/range.rb:39:in `initialize': Parser::Source::Range: end_pos must not be less than begin_pos (ArgumentError)

          raise ArgumentError, 'Parser::Source::Range: end_pos must not be less than begin_pos'
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/tokenizer/location.rb:23:in `initialize'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:214:in `new'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:214:in `build_location'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:206:in `build_node'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:177:in `build_attribute_node'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:151:in `build_tag_attributes_node'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:133:in `build_tag_node'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:79:in `build_document_node'
        from /home/earlopain/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/better_html-2.1.1/lib/better_html/parser.rb:49:in `ast'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant