From 55c86cede461ac832e833b9d249eb129eb7cc457 Mon Sep 17 00:00:00 2001 From: Paul Padier Date: Wed, 20 Jul 2022 14:27:23 +0900 Subject: [PATCH 1/3] Test on Ruby@head as well --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index edd6c2d..fe492a5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0' - ruby: [2.2, 2.3, 2.4, 2.5, 2.6, 2.7, '3.0', 3.1, truffleruby] + ruby: [2.2, 2.3, 2.4, 2.5, 2.6, 2.7, '3.0', 3.1, head, truffleruby] include: - { ruby: jruby-9.3, allow-failure: true } steps: From 0aa3ce368605139b8a79f0d0ea8dfc269dcecb52 Mon Sep 17 00:00:00 2001 From: Paul Padier Date: Wed, 20 Jul 2022 14:31:32 +0900 Subject: [PATCH 2/3] Update Node.parse parameter definition to work in Ruby 3.2 An alternative would be to mark the method with `ruby2_keywords`: From the Ruby 3.2 changelog: > Methods taking a rest parameter (like `*args`) and wishing to delegate keyword arguments through `foo(*args)` must now be marked with `ruby2_keywords` (if not already the case). In other words, all methods wishing to delegate keyword arguments through `*args` must now be marked with `ruby2_keywords`, with no exception. This will make it easier to transition to other ways of delegation once a library can require Ruby 3+. Previously, the `ruby2_keywords` flag was kept if the receiving method took `*args`, but this was a bug and an inconsistency. A good technique to find the potentially-missing `ruby2_keywords` is to run the test suite, for where it fails find the last method which must receive keyword arguments, use `puts nil, caller, nil` there, and check each method/block on the call chain which must delegate keywords is correctly marked as `ruby2_keywords`. [[Bug #18625](https://bugs.ruby-lang.org/issues/18625)] [[Bug #16466](https://bugs.ruby-lang.org/issues/16466)] `Node.parse` takes `*args` and delegates them to `Node.new`, therefore it needs to be marked with `ruby2_keywords`. --- mustermann/lib/mustermann/ast/node.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mustermann/lib/mustermann/ast/node.rb b/mustermann/lib/mustermann/ast/node.rb index abd5052..b846e57 100644 --- a/mustermann/lib/mustermann/ast/node.rb +++ b/mustermann/lib/mustermann/ast/node.rb @@ -35,8 +35,8 @@ def self.constant_name(name) # Helper for creating a new instance and calling #parse on it. # @return [Mustermann::AST::Node] # @!visibility private - def self.parse(*args, &block) - new(*args).tap { |n| n.parse(&block) } + def self.parse(payload = nil, **options, &block) + new(payload, **options).tap { |n| n.parse(&block) } end # @!visibility private From 8be5bd4ac3642d9c9582d0a7258f3197fa54bb96 Mon Sep 17 00:00:00 2001 From: Paul Padier Date: Wed, 20 Jul 2022 22:32:25 +0900 Subject: [PATCH 3/3] Don't call #=~ on objects that don't respond to it `Kernel` defined `#=~` up until Ruby 3.2, but it just returned `nil` when the method wasn't redefined by a child class. --- mustermann/lib/mustermann/ast/expander.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mustermann/lib/mustermann/ast/expander.rb b/mustermann/lib/mustermann/ast/expander.rb index 6cb9110..f5ca874 100644 --- a/mustermann/lib/mustermann/ast/expander.rb +++ b/mustermann/lib/mustermann/ast/expander.rb @@ -124,6 +124,8 @@ def error_for(values) # @see Mustermann::AST::Translator#expand # @!visibility private ruby2_keywords def escape(string, *args) + return super unless string.respond_to?(:=~) + # URI::Parser is pretty slow, let's not send every string to it, even if it's unnecessary string =~ /\A\w*\Z/ ? string : super end