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 (ArgumentError) invalid byte sequence in UTF-8 #995

Merged
merged 1 commit into from
May 19, 2022

Conversation

ksss
Copy link
Collaborator

@ksss ksss commented May 13, 2022

I exec $ rb prototype rb on the following file and found the problem.

https://github.com/rails/rails/blob/b5630e232b95859c4171a285cd8f130e37d3c501/activesupport/lib/active_support/core_ext/digest/uuid.rb

$ rbs prototype rb activesupport/lib/active_support/core_ext/digest/uuid.rb
/Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rbs-2.4.0/lib/rbs/prototype/rb.rb:488:in `match?': invalid byte sequence in UTF-8 (ArgumentError)
	from /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rbs-2.4.0/lib/rbs/prototype/rb.rb:488:in `literal_to_type'
	from /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rbs-2.4.0/lib/rbs/prototype/rb.rb:341:in `process'
	from /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rbs-2.4.0/lib/rbs/prototype/rb.rb:357:in `block in process_children'
	from /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rbs-2.4.0/lib/rbs/prototype/helpers.rb:74:in `block in each_node'
	from /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rbs-2.4.0/lib/rbs/prototype/helpers.rb:72:in `each'
	from /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rbs-2.4.0/lib/rbs/prototype/helpers.rb:72:in `each_node'
	from /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rbs-2.4.0/lib/rbs/prototype/helpers.rb:68:in `each_child'
	from /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rbs-2.4.0/lib/rbs/prototype/rb.rb:356:in `process_children'
	from /Users/ksss/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rbs-2.4.0/lib/rbs/prototype/rb.rb:351:in `process'

I suggest using String#ascii_only? since the original Regexp(/\A[ -~]+\z/) seemed to be determining if it was an ascii string only.

As a side effect, strings like "" and "foo\nbar", which were not previously converted as literals, are now recognized as literals.

Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@soutaro soutaro merged commit 86739c4 into ruby:master May 19, 2022
@ksss ksss deleted the invalid_byte_sequence_in_utf8 branch May 19, 2022 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants