Project

General

Profile

Backport #8856

gsub doesn't work properly with \K

Added by k_takata (Ken Takata) about 5 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Normal
[ruby-dev:47694]

Description

Regexp#gsub で \K を使うと、正しく動作しないようです。
Regexp#sub は問題ありません。

http://rubyist.g.hatena.ne.jp/n2s/20130714/p1 より、

% irb-ruby-2.0.0-p247
2.0.0p247 :001 > a="foobarbazquux/foobarbazquux"
=> "foobarbazquux/foobarbazquux"
2.0.0p247 :002 > a.sub(/foo\Kbar/, "")
=> "foobazquux/foobarbazquux"
2.0.0p247 :003 > a.gsub(/foo\Kbar/, "")
=> "bazquux/bazquux"

Associated revisions

Revision b31965cb
Added by nobu (Nobuyoshi Nakada) about 5 years ago

string.c: fix for \K

  • string.c (str_gsub): use BEG(0) for whole matched position not return value from rb_reg_search(), for \K matching. [Bug #8856]

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

Revision 42820
Added by nobu (Nobuyoshi Nakada) about 5 years ago

string.c: fix for \K

  • string.c (str_gsub): use BEG(0) for whole matched position not return value from rb_reg_search(), for \K matching. [Bug #8856]

Revision 42820
Added by nobu (Nobuyoshi Nakada) about 5 years ago

string.c: fix for \K

  • string.c (str_gsub): use BEG(0) for whole matched position not return value from rb_reg_search(), for \K matching. [Bug #8856]

Revision 42820
Added by nobu (Nobuyoshi Nakada) about 5 years ago

string.c: fix for \K

  • string.c (str_gsub): use BEG(0) for whole matched position not return value from rb_reg_search(), for \K matching. [Bug #8856]

Revision 42820
Added by nobu (Nobuyoshi Nakada) about 5 years ago

string.c: fix for \K

  • string.c (str_gsub): use BEG(0) for whole matched position not return value from rb_reg_search(), for \K matching. [Bug #8856]

Revision 42820
Added by nobu (Nobuyoshi Nakada) about 5 years ago

string.c: fix for \K

  • string.c (str_gsub): use BEG(0) for whole matched position not return value from rb_reg_search(), for \K matching. [Bug #8856]

Revision 45ce4608
Added by nagachika (Tomoyuki Chikanaga) about 5 years ago

merge revision(s) 42820: [Backport #8856]

* string.c (str_gsub): use BEG(0) for whole matched position not
  return value from rb_reg_search(), for \K matching.
   [Bug #8856]

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

Revision 42915
Added by nagachika (Tomoyuki Chikanaga) about 5 years ago

merge revision(s) 42820: [Backport #8856]

* string.c (str_gsub): use BEG(0) for whole matched position not
  return value from rb_reg_search(), for \K matching.
   [Bug #8856]

History

#1 [ruby-dev:47696] Updated by nobu (Nobuyoshi Nakada) about 5 years ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: DONTNEED, 2.0.0: REQUIRED

#2 Updated by nobu (Nobuyoshi Nakada) about 5 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r42820.
Ken, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


string.c: fix for \K

  • string.c (str_gsub): use BEG(0) for whole matched position not return value from rb_reg_search(), for \K matching. [Bug #8856]

#3 Updated by nagachika (Tomoyuki Chikanaga) about 5 years ago

  • Category deleted (regexp)
  • Status changed from Closed to Assigned
  • Assignee set to nagachika (Tomoyuki Chikanaga)
  • Tracker changed from Bug to Backport
  • Project changed from Ruby trunk to Backport200

#4 Updated by nagachika (Tomoyuki Chikanaga) about 5 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r42915.
Ken, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 42820: [Backport #8856]

* string.c (str_gsub): use BEG(0) for whole matched position not
  return value from rb_reg_search(), for \K matching.
   [Bug #8856]

Also available in: Atom PDF