You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ ruby example.rb
Loaded suite example
Started
.
Finished in 0.000961 seconds.
---------------------------------------------------------------------------------------------------------
1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
---------------------------------------------------------------------------------------------------------
$ rubocop -a example.rb
Inspecting 1 file
C
Offenses:
example.rb:10:26: C: [Corrected] Use %q only for strings that contain both single quotes and double quotes.
target.gsub('foo', %q(\\\')) == expected
^^^^^^^^
1 file inspected, 1 offense detected, 1 offense corrected
ruby example.rb
Loaded suite example
Started
F
=========================================================================================================
Failure:
target.gsub('foo', "\\\'") == expected
| | | |
| | | "\\'bar"
| | false
| "barbar"
"foobar"
test: replace(TestSample)
/Users/tony/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/power_assert-0.2.6/lib/power_assert.rb:36:in `start'
example.rb:9:in `block in <class:TestSample>'
6: test 'replace' do
7: target = 'foobar'
8: expected = "\\'bar"
=> 9: assert do
10: target.gsub('foo', "\\\'") == expected
11: end
12: end
=========================================================================================================
Finished in 0.005932 seconds.
---------------------------------------------------------------------------------------------------------
1 tests, 1 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
0% passed
---------------------------------------------------------------------------------------------------------
The text was updated successfully, but these errors were encountered:
tonymarklove
changed the title
Replacement of %q when escape characters are present can break code
Replacement of %q when escape characters are present can break code
Jul 8, 2016
owst
pushed a commit
to owst/rubocop
that referenced
this issue
Jul 19, 2016
The rule that replaces
%q
with a double quote string literal is not correct in the presence of both an escaped backslash and an escaped single quote.Our real use case was to replace
'hello'
(quotes are part of the string) with\'hello\'
.Expected behavior
No change.
Actual behavior
Steps to reproduce the problem
example.rb
RuboCop version
The text was updated successfully, but these errors were encountered: