summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Gee <michaelpgee@gmail.com>2018-04-15 19:59:06 -0400
committerMichael Gee <michaelpgee@gmail.com>2018-04-29 10:17:10 -0400
commitece8625e60a0d83af2003f5265bf552c1c0dc460 (patch)
tree08562a15520da4602f8526bf6776ed995b3752b5
parentd8d688164f4ec316b1e18e3b63090df9450aa8d5 (diff)
downloadrack-ece8625e60a0d83af2003f5265bf552c1c0dc460.tar.gz
Strip unicode byte order mark from UTF8 config.ru
-rw-r--r--lib/rack/builder.rb3
-rw-r--r--test/builder/bom.ru1
-rw-r--r--test/spec_builder.rb7
3 files changed, 10 insertions, 1 deletions
diff --git a/lib/rack/builder.rb b/lib/rack/builder.rb
index fc36b371..d1d07ff5 100644
--- a/lib/rack/builder.rb
+++ b/lib/rack/builder.rb
@@ -31,10 +31,13 @@ module Rack
# You can use +map+ to construct a Rack::URLMap in a convenient way.
class Builder
+ UTF_8_BOM = '\xef\xbb\xbf'
+
def self.parse_file(config, opts = Server::Options.new)
options = {}
if config =~ /\.ru$/
cfgfile = ::File.read(config)
+ cfgfile.slice!(/\A#{UTF_8_BOM}/) if cfgfile.encoding == Encoding::UTF_8
if cfgfile[/^#\\(.*)/] && opts
options = opts.parse! $1.split(/\s+/)
end
diff --git a/test/builder/bom.ru b/test/builder/bom.ru
new file mode 100644
index 00000000..3f023393
--- /dev/null
+++ b/test/builder/bom.ru
@@ -0,0 +1 @@
+run -> (env) { [200, {'Content-Type' => 'text/plain'}, ['OK']] }
diff --git a/test/spec_builder.rb b/test/spec_builder.rb
index 40e602e8..66c7bf7f 100644
--- a/test/spec_builder.rb
+++ b/test/spec_builder.rb
@@ -199,7 +199,7 @@ describe Rack::Builder do
end)
o = Object.new
def o.call(env)
- @a = 1 if env['PATH_INFO'] == '/b';
+ @a = 1 if env['PATH_INFO'] == '/b';
[200, {}, []]
end
run o
@@ -258,6 +258,11 @@ describe Rack::Builder do
app, _ = Rack::Builder.parse_file config_file('line.ru')
Rack::MockRequest.new(app).get("/").body.to_s.must_equal '1'
end
+
+ it "strips leading unicode byte order mark when present" do
+ app, _ = Rack::Builder.parse_file config_file('bom.ru')
+ Rack::MockRequest.new(app).get("/").body.to_s.must_equal 'OK'
+ end
end
describe 'new_from_string' do