Project

General

Profile

Bug #11132

String#sub and character sequence \' in replacement string

Added by gettalong (Thomas Leitner) over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
[ruby-core:69121]

Description

Hi,

I don't know if this is intentional but substitution of \' and \` in the replacement string was rather unexpected for me:

2.2.2 :001 > "this is a test".sub(/this/, "some text \\'")
 => "some text  is a test is a test"

I would have expected the following result:

 => "some text \\' is a test"

The documentation says nothing about this, just that back-references can be used (i.e. \\d or \\k<n>).

A work-around is escaping the escape character:

2.2.2 :001 > "this is a test".sub(/this/, "some text \\\\'")                                                                                          
 => "some text \\' is a test"

Thanks!

Associated revisions

Revision 5ffb21eb
Added by hsbt (Hiroshi SHIBATA) over 4 years ago

  • string.c: added documentation for character sequence \' with String#sub [Bug #11132][ruby-core:69121][fix GH-900][ci skip] Patch by shishir127 (Shishir Joshi)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 50509
Added by hsbt (Hiroshi SHIBATA) over 4 years ago

  • string.c: added documentation for character sequence \' with String#sub [Bug #11132][ruby-core:69121][fix GH-900][ci skip] Patch by shishir127 (Shishir Joshi)

Revision 50509
Added by hsbt (Hiroshi SHIBATA) over 4 years ago

  • string.c: added documentation for character sequence \' with String#sub [Bug #11132][ruby-core:69121][fix GH-900][ci skip] Patch by shishir127 (Shishir Joshi)

Revision 50509
Added by hsbt (Hiroshi SHIBATA) over 4 years ago

  • string.c: added documentation for character sequence \' with String#sub [Bug #11132][ruby-core:69121][fix GH-900][ci skip] Patch by shishir127 (Shishir Joshi)

Revision 50509
Added by hsbt (Hiroshi SHIBATA) over 4 years ago

  • string.c: added documentation for character sequence \' with String#sub [Bug #11132][ruby-core:69121][fix GH-900][ci skip] Patch by shishir127 (Shishir Joshi)

Revision 50509
Added by hsbt (Hiroshi SHIBATA) over 4 years ago

  • string.c: added documentation for character sequence \' with String#sub [Bug #11132][ruby-core:69121][fix GH-900][ci skip] Patch by shishir127 (Shishir Joshi)

Revision a2126a67
Added by usa (Usaku NAKAMURA) over 4 years ago

merge revision(s) 50509: [Backport #11132]

    * string.c: added documentation for character sequence \' with String#sub
      [Bug #11132][ruby-core:69121][fix GH-900][ci skip] Patch by @shishir127

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@50582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 50582
Added by usa (Usaku NAKAMURA) over 4 years ago

merge revision(s) 50509: [Backport #11132]

* string.c: added documentation for character sequence \' with String#sub
  [Bug #11132][ruby-core:69121][fix GH-900][ci skip] Patch by @shishir127

Revision 637d0824
Added by nagachika (Tomoyuki Chikanaga) over 4 years ago

merge revision(s) 50509: [Backport #11132]

    * string.c: added documentation for character sequence \' with String#sub
      [Bug #11132][ruby-core:69121][fix GH-900][ci skip] Patch by @shishir127

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@50628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 50628
Added by nagachika (Tomoyuki Chikanaga) over 4 years ago

merge revision(s) 50509: [Backport #11132]

* string.c: added documentation for character sequence \' with String#sub
  [Bug #11132][ruby-core:69121][fix GH-900][ci skip] Patch by @shishir127

History

Updated by nobu (Nobuyoshi Nakada) over 4 years ago

It's a spec, but seems there is no docs about it.
This is a documentation issue.

#2

Updated by hsbt (Hiroshi SHIBATA) over 4 years ago

  • Status changed from Open to Closed

Applied in changeset r50509.


  • string.c: added documentation for character sequence \' with String#sub [Bug #11132][ruby-core:69121][fix GH-900][ci skip] Patch by shishir127 (Shishir Joshi)
#3

Updated by usa (Usaku NAKAMURA) over 4 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: WONTFIX, 2.1: REQUIRED, 2.2: REQUIRED
#4

Updated by usa (Usaku NAKAMURA) over 4 years ago

  • Backport changed from 2.0.0: WONTFIX, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: WONTFIX, 2.1: DONE, 2.2: REQUIRED

ruby_2_1 r50582 merged revision(s) 50509.

Updated by nagachika (Tomoyuki Chikanaga) over 4 years ago

  • Backport changed from 2.0.0: WONTFIX, 2.1: DONE, 2.2: REQUIRED to 2.0.0: WONTFIX, 2.1: DONE, 2.2: DONE

Backported into ruby_2_2 branch at r50628.

Also available in: Atom PDF