* [ruby-core:63616] [ruby-trunk - Bug #10022] [Open] Inconsistent behavior of gsub replacement
[not found] <redmine.issue-10022.20140710003935@ruby-lang.org>
@ 2014-07-10 0:39 ` franklsf95
2014-07-10 0:45 ` [ruby-core:63617] [ruby-trunk - Bug #10022] [Rejected] " nobu
1 sibling, 0 replies; 2+ messages in thread
From: franklsf95 @ 2014-07-10 0:39 UTC (permalink / raw
To: ruby-core
Issue #10022 has been reported by Frank Luan.
----------------------------------------
Bug #10022: Inconsistent behavior of gsub replacement
https://bugs.ruby-lang.org/issues/10022
* Author: Frank Luan
* Status: Open
* Priority: Normal
* Assignee:
* Category: regexp
* Target version:
* ruby -v: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
In the following code, the two gsub's yield different results. ([[https://gist.github.com/franklsf95/6c0f8938f28706b5644d]])
~~~
ver = 9999
str = "\t<key>CFBundleDevelopmentRegion</key>\n\t<string>en</string>\n\t<key>CFBundleVersion</key>\n\t<string>0.1.190</string>\n\t<key>AppID</key>\n\t<string>000000000000000</string>"
puts str.gsub /(CFBundleVersion<\/key>\n\t.*\.).*(<\/string>)/, "#{$1}#{ver}#{$2}"
puts '--------'
puts str.gsub /(CFBundleVersion<\/key>\n\t.*\.).*(<\/string>)/, "#{$1}#{ver}#{$2}"
~~~
My running result is:
~~~
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>9999
<key>AppID</key>
<string>000000000000000</string>
--------
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleVersion</key>
<string>0.1.9999</string>
<key>AppID</key>
<string>000000000000000</string>
~~~
...which is strangely inconsistent.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
* [ruby-core:63617] [ruby-trunk - Bug #10022] [Rejected] Inconsistent behavior of gsub replacement
[not found] <redmine.issue-10022.20140710003935@ruby-lang.org>
2014-07-10 0:39 ` [ruby-core:63616] [ruby-trunk - Bug #10022] [Open] Inconsistent behavior of gsub replacement franklsf95
@ 2014-07-10 0:45 ` nobu
1 sibling, 0 replies; 2+ messages in thread
From: nobu @ 2014-07-10 0:45 UTC (permalink / raw
To: ruby-core
Issue #10022 has been updated by Nobuyoshi Nakada.
Description updated
Status changed from Open to Rejected
The second argument is evaluated **before** calling `gsub` method.
Call it with a block:
~~~ruby
puts str.gsub(/(CFBundleVersion<\/key>\n\t.*\.).*(<\/string>)/) {"#{$1}#{ver}#{$2}"}
~~~
----------------------------------------
Bug #10022: Inconsistent behavior of gsub replacement
https://bugs.ruby-lang.org/issues/10022#change-47670
* Author: Frank Luan
* Status: Rejected
* Priority: Normal
* Assignee:
* Category: regexp
* Target version:
* ruby -v: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
In the following code, the two gsub's yield different results. ([[https://gist.github.com/franklsf95/6c0f8938f28706b5644d]])
~~~ruby
ver = 9999
str = "\t<key>CFBundleDevelopmentRegion</key>\n\t<string>en</string>\n\t<key>CFBundleVersion</key>\n\t<string>0.1.190</string>\n\t<key>AppID</key>\n\t<string>000000000000000</string>"
puts str.gsub /(CFBundleVersion<\/key>\n\t.*\.).*(<\/string>)/, "#{$1}#{ver}#{$2}"
puts '--------'
puts str.gsub /(CFBundleVersion<\/key>\n\t.*\.).*(<\/string>)/, "#{$1}#{ver}#{$2}"
~~~
My running result is:
~~~
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>9999
<key>AppID</key>
<string>000000000000000</string>
--------
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleVersion</key>
<string>0.1.9999</string>
<key>AppID</key>
<string>000000000000000</string>
~~~
...which is strangely inconsistent.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-07-10 0:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <redmine.issue-10022.20140710003935@ruby-lang.org>
2014-07-10 0:39 ` [ruby-core:63616] [ruby-trunk - Bug #10022] [Open] Inconsistent behavior of gsub replacement franklsf95
2014-07-10 0:45 ` [ruby-core:63617] [ruby-trunk - Bug #10022] [Rejected] " 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).