Permalink
Browse files

Replace Gem::Version comparison with "\u2028" == 'u2028' comparison.

This ensures that the Unicode character is properly translated without relying on Gem::Version. Thanks to @judofyr.
  • Loading branch information...
benmanns committed Sep 26, 2011
1 parent 4122df8 commit 2b3d626f30f1826ef4609724893263402592d8e3
Showing with 3 additions and 3 deletions.
  1. +1 −1 lib/rack/contrib/jsonp.rb
  2. +2 −2 test/spec_rack_jsonp.rb
@@ -83,7 +83,7 @@ def pad(callback, response, body = "")
# replacing them with the escaped version. This should be safe because
# according to the JSON spec, these characters are *only* valid inside
# a string and should therefore not be present any other places.
- body << if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('1.9')
+ body << unless "\u2028" == 'u2028'
s.to_s.gsub("\u2028", '\u2028').gsub("\u2029", '\u2029')
else
# In 1.8
View
@@ -53,7 +53,7 @@
end
specify "should not allow literal U+2028 or U+2029" do
- test_body = if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('1.9')
+ test_body = unless "\u2028" == 'u2028'
"{\"bar\":\"\u2028 and \u2029\"}"
else
"{\"bar\":\"\342\200\250 and \342\200\251\"}"
@@ -62,7 +62,7 @@
app = lambda { |env| [200, {'Content-Type' => 'application/json'}, [test_body]] }
request = Rack::MockRequest.env_for("/", :params => "foo=bar&callback=#{callback}")
body = Rack::JSONP.new(app).call(request).last
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('1.9')
+ unless "\u2028" == 'u2028'
body.join.should.not.match(/\u2028|\u2029/)
else
body.join.should.not.match(/\342\200\250|\342\200\251/)

0 comments on commit 2b3d626

Please sign in to comment.