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 some 6-1-stable tests for Ruby 2.5 and 2.6 #45074
Conversation
tag.public_send(:"the-name", COMMON_DANGEROUS_CHARS => "the value", escape: false) | ||
if RUBY_VERSION >= "2.7" | ||
assert_equal "<the-name #{escaped_dangerous_chars}=\"the value\"></the-name>", | ||
tag.public_send(:"the-name", COMMON_DANGEROUS_CHARS => "the value") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried:
tag.public_send(:"the-name", COMMON_DANGEROUS_CHARS => "the value") | |
tag.public_send(:"the-name", { COMMON_DANGEROUS_CHARS => "the value" }) |
Pretty sure that will work across versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That still fails:
def tag_string(name, content = nil, **options, &block)
puts "#{name}, #{content}, #{options.inspect}"
end
tag_string('a-name', "abc" => "def")
# a-name, {"abc"=>"def"}, {}
tag_string('a-name', {"abc" => "def"})
# a-name, {"abc"=>"def"}, {}
tag_string('a-name', :abc => "def")
# a-name, , {:abc=>"def"}
I've changed the PR to call to_sym
on the key instead.
6-1-stable currently has failing tests: https://buildkite.com/rails/rails/builds/86353 assert_equal "<the-name #{escaped_dangerous_chars}=\"the value\"></the-name>", tag.public_send(:"the-name", COMMON_DANGEROUS_CHARS => "the value") TagHelperTest#test_tag_builder_with_dangerous_unknown_attribute_name [/rails/actionview/test/template/tag_helper_test.rb:179]: --- expected +++ actual @@ -1 +1 @@ -"<the-name _______________=\"the value\"></the-name>" +"<the-name>{"&<>\\"&rails#39; %*+,/;=^|"=>"the value"}</the-name>" The test fails because the `attributes` hash argument has string keys. In Ruby 2.5 and 2.6 only Symbol keys are allowed in keyword arguments. So the argument is seen as the `content` argument for the tag instead of the `attributes`. This test was introduced in 123f42a. Running the test prior to 123f42a generates the same error. Calling `to_sym` on the key fixes the test.
7735a94
to
507b5aa
Compare
You're right, after digging into this myself, I realized that hash is passed to |
Thanks! I think this should be backported to 6-0-stable as well: |
Should I create a PR? |
Nah don't worry, I'll cherry-pick the commit. |
Fix some 6-1-stable tests for Ruby 2.5 and 2.6
Summary
6-1-stable currently has failing tests: https://buildkite.com/rails/rails/builds/86353
The test fails because the
attributes
hash argument has string keys.In Ruby 2.5 and 2.6 only Symbol keys are allowed in keyword arguments.
So the argument is seen as the
content
argument for the tag instead of theattributes
.This test was introduced in 123f42a.
Running the test prior to 123f42a generates the same error.
Calling
to_sym
on the key fixes the test.A simpler solution would be skipping this test altogether for Ruby 2.7, but
then we might miss future regressions.