diff --git a/changelog/fix_fix_stylequotedsymbols_handling_escaped.md b/changelog/fix_fix_stylequotedsymbols_handling_escaped.md new file mode 100644 index 00000000000..2b2272faa43 --- /dev/null +++ b/changelog/fix_fix_stylequotedsymbols_handling_escaped.md @@ -0,0 +1 @@ +* [#10148](https://github.com/rubocop/rubocop/issues/10148): Fix `Style/QuotedSymbols` handling escaped characters incorrectly. ([@dvandersluis][]) diff --git a/lib/rubocop/cop/mixin/string_literals_help.rb b/lib/rubocop/cop/mixin/string_literals_help.rb index c43c08dc176..b9d7677dec7 100644 --- a/lib/rubocop/cop/mixin/string_literals_help.rb +++ b/lib/rubocop/cop/mixin/string_literals_help.rb @@ -13,7 +13,11 @@ def wrong_quotes?(src_or_node) if style == :single_quotes !double_quotes_required?(src) else - !/" | \\[^'\\] | \#[@{$]/x.match?(src) + # The string needs single quotes if: + # 1. It contains a double quote + # 2. It contains text that would become an escape sequence with double quotes + # 3. It contains text that would become an interpolation with double quotes + !/" | (?