Skip to content

Parsing code with an invalid encoding raises #998

Closed
@Earlopain

Description

@Earlopain
Parser::CurrentRuby.parse("# encoding: utf")

# /home/earlopain/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/source/buffer.rb:69:in `find': unknown encoding name - utf (ArgumentError)
#
#          Encoding.find(result[3] || result[4] || result[6])

Ruby does raise an error when trying to execute the file:

[earlopain@DESKTOP-PC whitequark-parser]$ ruby test.rb
test.rb:1: unknown encoding name: utf (ArgumentError)

It doesn't look like a SyntaxError, not quite sure what this actually is, where it's coming from. However I believe the parser gem here shouldn't raise an ArgumentError in this case. This makes tools like RuboCop raise as well when trying to analyze these invalid files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions