summaryrefslogtreecommitdiffstats
path: root/sample
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-17 05:37:23 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-17 05:37:23 +0000
commit6d66fcab264406bc9d5aef7f0cd3e1467969008f (patch)
tree0f11eab709ada7fa915559d790de3cace2b2ec38 /sample
parent0d8980cef3c36089344c0d712d7b33d144db3d17 (diff)
downloadruby-6d66fcab264406bc9d5aef7f0cd3e1467969008f.tar.gz
ruby-6d66fcab264406bc9d5aef7f0cd3e1467969008f.tar.xz
ruby-6d66fcab264406bc9d5aef7f0cd3e1467969008f.zip
* sample/test.rb (valid_syntax?): skips BOM. [ruby-dev:38666]
* test/ruby/test_system.rb (TestSystem#valid_syntax?): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample')
-rw-r--r--sample/test.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/sample/test.rb b/sample/test.rb
index b0475c89f..b1560d310 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