From 45b8473fecf2b5e577701662ed9040aa2e281c87 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Wed, 2 Sep 2026 11:20:42 +0200 Subject: [PATCH 1/2] [ruby/prism] Fix `Comment#trailing` for syntax invalid edgecase When prism encounter invalid bytes and still switches over to parsing comments, `strip` will raise `syntax_suggest` might run into this via `ruby/spec` https://github.com/ruby/prism/commit/c72817c58b --- lib/prism/parse_result.rb | 2 ++ test/prism/result/comments_test.rb | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/prism/parse_result.rb b/lib/prism/parse_result.rb index 92eb56bf36220b..e9380d0f0991d4 100644 --- a/lib/prism/parse_result.rb +++ b/lib/prism/parse_result.rb @@ -744,6 +744,8 @@ class InlineComment < Comment #: () -> bool def trailing? !location.start_line_slice.strip.empty? + rescue ArgumentError # invalid bytes, never whitespace only + false end # Returns a string representation of this comment. diff --git a/test/prism/result/comments_test.rb b/test/prism/result/comments_test.rb index 178623a75ff688..140eddd5d17b67 100644 --- a/test/prism/result/comments_test.rb +++ b/test/prism/result/comments_test.rb @@ -39,6 +39,16 @@ def foo ) end + def test_comment_trailing + comment = Prism.parse_comments("x # trailing")[0] + assert_predicate(comment, :trailing?) + end + + def test_comment_syntax_invalid_bytes_trailing + comment = Prism.parse_comments("\xFF\xFE# not trailing")[0] + refute_predicate(comment, :trailing?) + end + def test___END__ result = Prism.parse(<<~RUBY) __END__ From 8568294f776f36ee04c9d56d965531366e0b157a Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 3 Sep 2026 19:55:14 +0200 Subject: [PATCH 2/2] Add NEWS.md entry for String#tr new capability --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index d36344025d544c..0e11240ad85538 100644 --- a/NEWS.md +++ b/NEWS.md @@ -130,6 +130,8 @@ Note: We're only listing outstanding class updates. `String#bit_count` handle individual bits, and `String#bitwise_not`, `String#bitwise_and`, `String#bitwise_or`, `String#bitwise_xor` (with their `!` variants) handle whole strings. [[Feature #22118]] + * `String#tr` now accept a Hash for multi-character replacement. + [[Feature #22238]] * Symbol @@ -376,6 +378,7 @@ A lot of work has gone into making Ractors more stable, performant, and usable. [Feature #22175]: https://bugs.ruby-lang.org/issues/22175 [Feature #22185]: https://bugs.ruby-lang.org/issues/22185 [Feature #22205]: https://bugs.ruby-lang.org/issues/22205 +[Feature #22238]: https://bugs.ruby-lang.org/issues/22238 [PR #17201]: https://github.com/ruby/ruby/pull/17201 [GH-psych #805]: https://github.com/ruby/psych/pull/805 [RubyGems-v4.0.4]: https://github.com/rubygems/rubygems/releases/tag/v4.0.4