ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:40122] [Ruby - Bug #1443] String#gsub handles backslashes incorrectly
       [not found] <redmine.issue-1443.20090507215953@ruby-lang.org>
@ 2011-10-12 17:38 ` Moxley Stratton
  2011-10-12 18:30   ` [ruby-core:40123] " Nikolai Weibull
  2011-10-13  4:08 ` [ruby-core:40131] " Moxley Stratton
  2011-10-13  4:27 ` [ruby-core:40133] " Moxley Stratton
  2 siblings, 1 reply; 4+ messages in thread
From: Moxley Stratton @ 2011-10-12 17:38 UTC (permalink / raw
  To: ruby-core


Issue #1443 has been updated by Moxley Stratton.


puts "\\"
\

puts "s".gsub("s", "\\")
\

puts "\\\\"
\\

puts "s".gsub("s", "\\\\")
\

gsub() returns inconsistent results. It should not modify the replacement string value.

string = File.read(some_file_with_backslashes_in_it)

string = "s".gsub("s", File.read(some_file_with_backslashes_in_it))

The above two examples should give the same result, but they don't. The file content has been modified by gsub(). It should not be modified.

This is not an issue with Ruby string literal syntax. It is an issue with gsub() and sub() methods.
----------------------------------------
Bug #1443: String#gsub handles backslashes incorrectly
http://redmine.ruby-lang.org/issues/1443

Author: shawn landen
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v:   ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]


=begin
 @Shyouhei Urabe
 
 I didn't see how to comment on the bug so i hid to file a new one
 This is a continuation of bug #1441
 
 The backslashes are being doubled under single quotes and double quotes, but String#gsub requires you to quadruple (4x) them, 4 backslashes for every one in the resultant string.
 
 printf "b".gsub("b","\\\\")
 
 prints a single backslash(\), while it should print 2(\\). (as printf "\\\\"; does)
 
 The reason it looks different is because String#inspect shows strings as escaped.
=end



-- 
http://redmine.ruby-lang.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:40123] Re: [Ruby - Bug #1443] String#gsub handles backslashes incorrectly
  2011-10-12 17:38 ` [ruby-core:40122] [Ruby - Bug #1443] String#gsub handles backslashes incorrectly Moxley Stratton
@ 2011-10-12 18:30   ` Nikolai Weibull
  0 siblings, 0 replies; 4+ messages in thread
From: Nikolai Weibull @ 2011-10-12 18:30 UTC (permalink / raw
  To: ruby-core

On Wed, Oct 12, 2011 at 19:38, Moxley Stratton
<moxley.stratton@gmail.com> wrote:

> puts "\\"
> \

> puts "s".gsub("s", "\\")
> \

There’s nothing to escape, thus “\”.

> puts "s".gsub("s", "\\\\")
> \

There’s a backslash to escape, thus “\”.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:40131] [Ruby - Bug #1443] String#gsub handles backslashes incorrectly
       [not found] <redmine.issue-1443.20090507215953@ruby-lang.org>
  2011-10-12 17:38 ` [ruby-core:40122] [Ruby - Bug #1443] String#gsub handles backslashes incorrectly Moxley Stratton
@ 2011-10-13  4:08 ` Moxley Stratton
  2011-10-13  4:27 ` [ruby-core:40133] " Moxley Stratton
  2 siblings, 0 replies; 4+ messages in thread
From: Moxley Stratton @ 2011-10-13  4:08 UTC (permalink / raw
  To: ruby-core


Issue #1443 has been updated by Moxley Stratton.


I understand now.

The replacement string value is parsed for pattern group references, such as \1.

http://redmine.ruby-lang.org/issues/1251

Thank you
----------------------------------------
Bug #1443: String#gsub handles backslashes incorrectly
http://redmine.ruby-lang.org/issues/1443

Author: shawn landen
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v:   ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]


=begin
 @Shyouhei Urabe
 
 I didn't see how to comment on the bug so i hid to file a new one
 This is a continuation of bug #1441
 
 The backslashes are being doubled under single quotes and double quotes, but String#gsub requires you to quadruple (4x) them, 4 backslashes for every one in the resultant string.
 
 printf "b".gsub("b","\\\\")
 
 prints a single backslash(\), while it should print 2(\\). (as printf "\\\\"; does)
 
 The reason it looks different is because String#inspect shows strings as escaped.
=end



-- 
http://redmine.ruby-lang.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:40133] [Ruby - Bug #1443] String#gsub handles backslashes incorrectly
       [not found] <redmine.issue-1443.20090507215953@ruby-lang.org>
  2011-10-12 17:38 ` [ruby-core:40122] [Ruby - Bug #1443] String#gsub handles backslashes incorrectly Moxley Stratton
  2011-10-13  4:08 ` [ruby-core:40131] " Moxley Stratton
@ 2011-10-13  4:27 ` Moxley Stratton
  2 siblings, 0 replies; 4+ messages in thread
From: Moxley Stratton @ 2011-10-13  4:27 UTC (permalink / raw
  To: ruby-core


Issue #1443 has been updated by Moxley Stratton.


I will use String#[]= instead:

string['pattern'] = File.read(some_file_with_backslashes_in_it)

This meets my requirements.
----------------------------------------
Bug #1443: String#gsub handles backslashes incorrectly
http://redmine.ruby-lang.org/issues/1443

Author: shawn landen
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v:   ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]


=begin
 @Shyouhei Urabe
 
 I didn't see how to comment on the bug so i hid to file a new one
 This is a continuation of bug #1441
 
 The backslashes are being doubled under single quotes and double quotes, but String#gsub requires you to quadruple (4x) them, 4 backslashes for every one in the resultant string.
 
 printf "b".gsub("b","\\\\")
 
 prints a single backslash(\), while it should print 2(\\). (as printf "\\\\"; does)
 
 The reason it looks different is because String#inspect shows strings as escaped.
=end



-- 
http://redmine.ruby-lang.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-10-13  4:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-1443.20090507215953@ruby-lang.org>
2011-10-12 17:38 ` [ruby-core:40122] [Ruby - Bug #1443] String#gsub handles backslashes incorrectly Moxley Stratton
2011-10-12 18:30   ` [ruby-core:40123] " Nikolai Weibull
2011-10-13  4:08 ` [ruby-core:40131] " Moxley Stratton
2011-10-13  4:27 ` [ruby-core:40133] " Moxley Stratton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).