aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--sample/test.rb7
-rw-r--r--test/ruby/test_system.rb5
3 files changed, 13 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index f2e4055214..1f027943d9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Jun 17 14:37:18 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * sample/test.rb (valid_syntax?): skips BOM. [ruby-dev:38666]
+
+ * test/ruby/test_system.rb (TestSystem#valid_syntax?): ditto.
+
Wed Jun 17 13:54:18 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/strscan/strscan.c (Init_strscan): remove obsolete
diff --git a/sample/test.rb b/sample/test.rb
index b0475c89f6..b1560d3105 100644
--- a/sample/test.rb
+++ b/sample/test.rb
@@ -1930,10 +1930,11 @@ end
def valid_syntax?(code, fname)
p fname
- code.force_encoding("ascii-8bit")
- code = code.sub(/\A(?:\s*\#.*$)*(\n)?/n) {
+ code = code.dup.force_encoding("ascii-8bit")
+ code.sub!(/\A(\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) {
"#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ok}\n"
- }.force_encoding("us-ascii")
+ }
+ code.force_encoding("us-ascii")
catch {|tag| eval(code, binding, fname, 0)}
rescue Exception
STDERR.puts $!.message
diff --git a/test/ruby/test_system.rb b/test/ruby/test_system.rb
index 4aae0d54f1..2143fcad71 100644
--- a/test/ruby/test_system.rb
+++ b/test/ruby/test_system.rb
@@ -4,10 +4,11 @@ require_relative 'envutil'
class TestSystem < Test::Unit::TestCase
def valid_syntax?(code, fname)
- code.force_encoding("ascii-8bit")
- code = code.sub(/\A(?:\s*\#.*$)*(\n)?/n) {
+ code = code.dup.force_encoding("ascii-8bit")
+ code.sub!(/\A(\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) {
"#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ok}\n"
}
+ code.force_encoding("us-ascii")
catch {|tag| eval(code, binding, fname, 0)}
end