Skip to content

Commit

Permalink
Force encoding of the Regex to ASCII-8BIT, to allow matching
Browse files Browse the repository at this point in the history
unicode expressions. (See snowman testcase).
  • Loading branch information
danlucraft committed Jan 15, 2012
1 parent 4a67277 commit 1abc4fc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@
pkg/*
tags
.DS_store
*.gem
5 changes: 4 additions & 1 deletion bin/rak
Expand Up @@ -175,7 +175,7 @@ END
[ '-e', '--line-end', GetoptLong::NO_ARGUMENT ],
[ '--eval', GetoptLong::REQUIRED_ARGUMENT ]
)

opt[:max_count] = nil
opt[:only_print_filelist] = false
opt[:print_filename] = true
Expand Down Expand Up @@ -489,6 +489,9 @@ END
str = "(?:" + str + ")$"
end
str = str.gsub("~bang", "!").gsub("~ques", "?")
if str.respond_to?(:force_encoding)
str.force_encoding("ASCII-8BIT")
end
if $use_onig
flags = opt[:ignore_case] ? Oniguruma::OPTION_IGNORECASE : nil
Oniguruma::ORegexp.new(str, :options => flags)
Expand Down
3 changes: 3 additions & 0 deletions spec/example2/snowman.txt
@@ -0,0 +1,3 @@

# ☃

9 changes: 8 additions & 1 deletion spec/rak_spec.rb
@@ -1,4 +1,4 @@

#encoding: utf-8
require "spec_helper"

describe "Rak", "with no options" do
Expand Down Expand Up @@ -71,6 +71,13 @@
1|rakefile rakefile *Canceron* rakefile
END
end

it "matches unicode snowmen" do
rak("☃", :dir => "example2").should == <<-END
*snowman.txt*
2|# *☃*
END
end
end

describe "Rak", "with FILE or STDIN inputs" do
Expand Down
6 changes: 5 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -40,7 +40,11 @@ def rak(args="", opts={})
cmd = "#{ruby_bin} #{bin_rak} #{args}"
cmd = "#{opts[:pipe]} | #{cmd}" if opts[:pipe]
ENV['RAK_TEST'] = "true" unless opts[:test_mode] == false
dir = opts[:dir] || HERE+"example"
if opts[:dir]
dir = HERE + opts[:dir]
else
dir = HERE + "example"
end
output = Dir.chdir(dir) do
%x{#{cmd}}
end
Expand Down

0 comments on commit 1abc4fc

Please sign in to comment.