Skip to content

Commit

Permalink
Merge pull request rubinius#1853 from walski/fix-1852
Browse files Browse the repository at this point in the history
Adds a conversion from Symbols to Strings in 1.9 Regexp#escape. Fixes rubinius#1852
  • Loading branch information
dbussink committed Aug 9, 2012
2 parents d47f143 + 246a26f commit 05cc511
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions kernel/common/regexp19.rb
Expand Up @@ -124,6 +124,7 @@ def self.union(*patterns)
end

def self.escape(str)
str = str.to_s if str.is_a?(Symbol)
escaped = StringValue(str).transform(ESCAPE_TABLE, true)
if escaped.ascii_only?
escaped.force_encoding Encoding::US_ASCII
Expand Down
4 changes: 4 additions & 0 deletions spec/ruby/core/regexp/shared/quote.rb
Expand Up @@ -9,6 +9,10 @@
end

ruby_version_is "1.9" do
it "works with symbols" do
Regexp.send(@method, :symbol).should == 'symbol'
end

it "sets the encoding of the result to US-ASCII if there are only US-ASCII characters present in the input String" do
str = encode("abc", "euc-jp")
Regexp.send(@method, str).encoding.should == Encoding::US_ASCII
Expand Down

0 comments on commit 05cc511

Please sign in to comment.