ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:71976] [Ruby trunk - Bug #11793] [Open] puts 'ab'.gsub('a', '\\+') - unexpected output
       [not found] <redmine.issue-11793.20151209053122@ruby-lang.org>
@ 2015-12-09  5:31 ` william.burnson
  2015-12-09  5:32 ` [ruby-core:71977] [Ruby trunk - Bug #11793] " william.burnson
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: william.burnson @ 2015-12-09  5:31 UTC (permalink / raw
  To: ruby-core

Issue #11793 has been reported by William Burnson.

----------------------------------------
Bug #11793: puts 'ab'.gsub('a', '\\+') - unexpected output
https://bugs.ruby-lang.org/issues/11793

* Author: William Burnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
Test case:
puts 'ab'.gsub('a', '\\+')

Expected output:
\+b

Actual output:
b

The way I understand gsub(pattern, replacement) when used with two string arguments is that it will perform a literal replacement, so it is quite unexpected that substituting with \+ removes the pattern entirely.

Doc: http://ruby-doc.org/core-2.2.3/String.html#method-i-gsub




-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:71977] [Ruby trunk - Bug #11793] puts 'ab'.gsub('a', '\\+') - unexpected output
       [not found] <redmine.issue-11793.20151209053122@ruby-lang.org>
  2015-12-09  5:31 ` [ruby-core:71976] [Ruby trunk - Bug #11793] [Open] puts 'ab'.gsub('a', '\\+') - unexpected output william.burnson
@ 2015-12-09  5:32 ` william.burnson
  2015-12-09  5:32 ` [ruby-core:71978] " william.burnson
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: william.burnson @ 2015-12-09  5:32 UTC (permalink / raw
  To: ruby-core

Issue #11793 has been updated by William Burnson.

Description updated

----------------------------------------
Bug #11793: puts 'ab'.gsub('a', '\\+') - unexpected output
https://bugs.ruby-lang.org/issues/11793#change-55385

* Author: William Burnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
Test case:
puts 'ab'.gsub('a', '\\\+')

Expected output:
\\+b

Actual output:
b

The way I understand gsub(pattern, replacement) when used with two string arguments is that it will perform a literal replacement, so it is quite unexpected that substituting with \+ removes the pattern entirely.

Doc: http://ruby-doc.org/core-2.2.3/String.html#method-i-gsub




-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:71978] [Ruby trunk - Bug #11793] puts 'ab'.gsub('a', '\\+') - unexpected output
       [not found] <redmine.issue-11793.20151209053122@ruby-lang.org>
  2015-12-09  5:31 ` [ruby-core:71976] [Ruby trunk - Bug #11793] [Open] puts 'ab'.gsub('a', '\\+') - unexpected output william.burnson
  2015-12-09  5:32 ` [ruby-core:71977] [Ruby trunk - Bug #11793] " william.burnson
@ 2015-12-09  5:32 ` william.burnson
  2015-12-09  5:33 ` [ruby-core:71979] " william.burnson
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: william.burnson @ 2015-12-09  5:32 UTC (permalink / raw
  To: ruby-core

Issue #11793 has been updated by William Burnson.

Description updated

----------------------------------------
Bug #11793: puts 'ab'.gsub('a', '\\+') - unexpected output
https://bugs.ruby-lang.org/issues/11793#change-55386

* Author: William Burnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
Test case:
~~~
puts 'ab'.gsub('a', '\\+')
~~~
Expected output:
~~~
\+b
~~~
Actual output:
~~~
b
~~~
The way I understand gsub(pattern, replacement) when used with two string arguments is that it will perform a literal replacement, so it is quite unexpected that substituting with \+ removes the pattern entirely.

Doc: http://ruby-doc.org/core-2.2.3/String.html#method-i-gsub




-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:71979] [Ruby trunk - Bug #11793] puts 'ab'.gsub('a', '\\+') - unexpected output
       [not found] <redmine.issue-11793.20151209053122@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2015-12-09  5:32 ` [ruby-core:71978] " william.burnson
@ 2015-12-09  5:33 ` william.burnson
  2015-12-09  5:34 ` [ruby-core:71980] " william.burnson
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: william.burnson @ 2015-12-09  5:33 UTC (permalink / raw
  To: ruby-core

Issue #11793 has been updated by William Burnson.

Description updated

----------------------------------------
Bug #11793: puts 'ab'.gsub('a', '\\+') - unexpected output
https://bugs.ruby-lang.org/issues/11793#change-55387

* Author: William Burnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
Test case:
puts 'ab'.gsub('a', '\\\\+')

Expected output:
\\+b

Actual output:
b

The way I understand gsub(pattern, replacement) when used with two string arguments is that it will perform a literal replacement, so it is quite unexpected that substituting with \+ removes the pattern entirely.

Doc: http://ruby-doc.org/core-2.2.3/String.html#method-i-gsub



-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:71980] [Ruby trunk - Bug #11793] puts 'ab'.gsub('a', '\\+') - unexpected output
       [not found] <redmine.issue-11793.20151209053122@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2015-12-09  5:33 ` [ruby-core:71979] " william.burnson
@ 2015-12-09  5:34 ` william.burnson
  2015-12-09  6:16 ` [ruby-core:71982] " hanmac
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: william.burnson @ 2015-12-09  5:34 UTC (permalink / raw
  To: ruby-core

Issue #11793 has been updated by William Burnson.

Description updated

----------------------------------------
Bug #11793: puts 'ab'.gsub('a', '\\+') - unexpected output
https://bugs.ruby-lang.org/issues/11793#change-55388

* Author: William Burnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
Test case:
puts 'ab'.gsub('a', '\\\\+')

Expected output:
\\+b

Actual output:
b

The way I understand gsub(pattern, replacement) when used with two string arguments is that it will perform a literal replacement, so it is quite unexpected that substituting with \\+ removes the pattern entirely.

Doc: http://ruby-doc.org/core-2.2.3/String.html#method-i-gsub



-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:71982] [Ruby trunk - Bug #11793] puts 'ab'.gsub('a', '\\+') - unexpected output
       [not found] <redmine.issue-11793.20151209053122@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2015-12-09  5:34 ` [ruby-core:71980] " william.burnson
@ 2015-12-09  6:16 ` hanmac
  2015-12-09  6:18 ` [ruby-core:71983] [Ruby trunk - Bug #11793] [Rejected] " usa
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: hanmac @ 2015-12-09  6:16 UTC (permalink / raw
  To: ruby-core

Issue #11793 has been updated by Hans Mackowiak.


its because how `gsub` works you need to escape the `\`

~~~ruby
puts 'ab'.gsub('a', '\\\+') #=> \+b
~~~

----------------------------------------
Bug #11793: puts 'ab'.gsub('a', '\\+') - unexpected output
https://bugs.ruby-lang.org/issues/11793#change-55391

* Author: William Burnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
Test case:
puts 'ab'.gsub('a', '\\\\+')

Expected output:
\\+b

Actual output:
b

The way I understand gsub(pattern, replacement) when used with two string arguments is that it will perform a literal replacement, so it is quite unexpected that substituting with \\+ removes the pattern entirely.

Doc: http://ruby-doc.org/core-2.2.3/String.html#method-i-gsub



-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:71983] [Ruby trunk - Bug #11793] [Rejected] puts 'ab'.gsub('a', '\\+') - unexpected output
       [not found] <redmine.issue-11793.20151209053122@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2015-12-09  6:16 ` [ruby-core:71982] " hanmac
@ 2015-12-09  6:18 ` usa
  2015-12-09  6:23 ` [ruby-core:71984] [Ruby trunk - Bug #11793] " matthew
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: usa @ 2015-12-09  6:18 UTC (permalink / raw
  To: ruby-core

Issue #11793 has been updated by Usaku NAKAMURA.

Status changed from Open to Rejected

----------------------------------------
Bug #11793: puts 'ab'.gsub('a', '\\+') - unexpected output
https://bugs.ruby-lang.org/issues/11793#change-55392

* Author: William Burnson
* Status: Rejected
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
Test case:
puts 'ab'.gsub('a', '\\\\+')

Expected output:
\\+b

Actual output:
b

The way I understand gsub(pattern, replacement) when used with two string arguments is that it will perform a literal replacement, so it is quite unexpected that substituting with \\+ removes the pattern entirely.

Doc: http://ruby-doc.org/core-2.2.3/String.html#method-i-gsub



-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:71984] [Ruby trunk - Bug #11793] puts 'ab'.gsub('a', '\\+') - unexpected output
       [not found] <redmine.issue-11793.20151209053122@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2015-12-09  6:18 ` [ruby-core:71983] [Ruby trunk - Bug #11793] [Rejected] " usa
@ 2015-12-09  6:23 ` matthew
  2015-12-09  6:26 ` [ruby-core:71986] " matthew
  2015-12-09  6:31 ` [ruby-core:71987] " nobu
  9 siblings, 0 replies; 10+ messages in thread
From: matthew @ 2015-12-09  6:23 UTC (permalink / raw
  To: ruby-core

Issue #11793 has been updated by Matthew Kerwin.


Substitution parameters work in string-string mode:

~~~
irb> puts 'ab'.gsub('a', %q(\`))
b
irb> puts 'ab'.gsub('a', %q(\&))
ab
irb> puts 'ab'.gsub('a', %q(\'))
bb
irb> puts 'ab'.gsub('a', %q(\0))
ab
irb> puts 'ab'.gsub('a', %q(\\0))
ab
irb> puts 'ab'.gsub('a', %q(\\\0))
\0b
irb> puts 'ab'.gsub('a', %q(\\\+))
\+b
~~~

I used `%q()` to make it clear just how many blackslashes are involved.

Note with the `\0` examples, either a single *or* double-backslash invokes the special value replacement.

The plus symbol (`$+` or `\+`) is an alias for the `$LAST_PAREN_MATCH` special value, which in this case is blank.

----------------------------------------
Bug #11793: puts 'ab'.gsub('a', '\\+') - unexpected output
https://bugs.ruby-lang.org/issues/11793#change-55393

* Author: William Burnson
* Status: Rejected
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
Test case:
puts 'ab'.gsub('a', '\\\\+')

Expected output:
\\+b

Actual output:
b

The way I understand gsub(pattern, replacement) when used with two string arguments is that it will perform a literal replacement, so it is quite unexpected that substituting with \\+ removes the pattern entirely.

Doc: http://ruby-doc.org/core-2.2.3/String.html#method-i-gsub



-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:71986] [Ruby trunk - Bug #11793] puts 'ab'.gsub('a', '\\+') - unexpected output
       [not found] <redmine.issue-11793.20151209053122@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2015-12-09  6:23 ` [ruby-core:71984] [Ruby trunk - Bug #11793] " matthew
@ 2015-12-09  6:26 ` matthew
  2015-12-09  6:31 ` [ruby-core:71987] " nobu
  9 siblings, 0 replies; 10+ messages in thread
From: matthew @ 2015-12-09  6:26 UTC (permalink / raw
  To: ruby-core

Issue #11793 has been updated by Matthew Kerwin.


I should have used this example:

~~~
puts 'ab'.gsub('a', "\x5C\x5C\x2B")
\+b
~~~

----------------------------------------
Bug #11793: puts 'ab'.gsub('a', '\\+') - unexpected output
https://bugs.ruby-lang.org/issues/11793#change-55395

* Author: William Burnson
* Status: Rejected
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
Test case:
puts 'ab'.gsub('a', '\\\\+')

Expected output:
\\+b

Actual output:
b

The way I understand gsub(pattern, replacement) when used with two string arguments is that it will perform a literal replacement, so it is quite unexpected that substituting with \\+ removes the pattern entirely.

Doc: http://ruby-doc.org/core-2.2.3/String.html#method-i-gsub



-- 
https://bugs.ruby-lang.org/

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

* [ruby-core:71987] [Ruby trunk - Bug #11793] puts 'ab'.gsub('a', '\\+') - unexpected output
       [not found] <redmine.issue-11793.20151209053122@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2015-12-09  6:26 ` [ruby-core:71986] " matthew
@ 2015-12-09  6:31 ` nobu
  9 siblings, 0 replies; 10+ messages in thread
From: nobu @ 2015-12-09  6:31 UTC (permalink / raw
  To: ruby-core

Issue #11793 has been updated by Nobuyoshi Nakada.

Description updated

The document states "It may contain back-references", `\+` is one of them.

Note: preformated text requires a preceding blank line.

----------------------------------------
Bug #11793: puts 'ab'.gsub('a', '\\+') - unexpected output
https://bugs.ruby-lang.org/issues/11793#change-55396

* Author: William Burnson
* Status: Rejected
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
Test case:

~~~ruby
puts 'ab'.gsub('a', '\\+')
~~~

Expected output:

~~~
\+b
~~~

Actual output:

~~~
b
~~~

The way I understand `gsub(pattern, replacement)` when used with two string arguments is that it will perform a literal replacement, so it is quite unexpected that substituting with `\+` removes the pattern entirely.

Doc: http://ruby-doc.org/core-2.2.3/String.html#method-i-gsub



-- 
https://bugs.ruby-lang.org/

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

end of thread, other threads:[~2015-12-09  6:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-11793.20151209053122@ruby-lang.org>
2015-12-09  5:31 ` [ruby-core:71976] [Ruby trunk - Bug #11793] [Open] puts 'ab'.gsub('a', '\\+') - unexpected output william.burnson
2015-12-09  5:32 ` [ruby-core:71977] [Ruby trunk - Bug #11793] " william.burnson
2015-12-09  5:32 ` [ruby-core:71978] " william.burnson
2015-12-09  5:33 ` [ruby-core:71979] " william.burnson
2015-12-09  5:34 ` [ruby-core:71980] " william.burnson
2015-12-09  6:16 ` [ruby-core:71982] " hanmac
2015-12-09  6:18 ` [ruby-core:71983] [Ruby trunk - Bug #11793] [Rejected] " usa
2015-12-09  6:23 ` [ruby-core:71984] [Ruby trunk - Bug #11793] " matthew
2015-12-09  6:26 ` [ruby-core:71986] " matthew
2015-12-09  6:31 ` [ruby-core:71987] " nobu

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).