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 string substitution regression #110

Merged
merged 2 commits into from
Aug 3, 2023
Merged

Fix string substitution regression #110

merged 2 commits into from
Aug 3, 2023

Conversation

nicoco007
Copy link
Contributor

Some of our tests started failing when updating from version 2.0.3. After some investigation, it turns out this change from #76 is the culprit – quotation marks are no longer escaped if the substitution value is a string since inspect isn't being called anymore. Reverting the change isn't possible since it would break some regular expressions so I've just added an exception here for strings.

@flavorjones
Copy link
Member

Would you consider fixing this instead by carving out an exception for Regexes (which is what #76 probably should have done)?

--- a/lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb
+++ b/lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb
@@ -19,10 +19,12 @@ def match(matches, attribute, matcher)
   private
     def matcher_for(value, format_for_presentation)
       # Nokogiri doesn't like arbitrary values without quotes, hence inspect.
       if format_for_presentation
         value.inspect # Avoid to_s so Regexps aren't put in quotes.
-      else
+      elsif value.is_a?(Regexp)
         "\"#{value}\""
+      else
+        value.to_s.inspect
       end
     end

@rafaelfranca rafaelfranca merged commit 6e8b754 into rails:main Aug 3, 2023
@nicoco007
Copy link
Contributor Author

Looks like Rafael beat me to the punch 😅 Yeah that makes more sense!

@nicoco007 nicoco007 deleted the fix-substitution-regression branch August 3, 2023 14:36
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.

3 participants