Skip to content

Loading…

Fix regexp to use case-insensitivity correctly #889

Open
wants to merge 1 commit into from

5 participants

@rennex

I noticed a faulty regexp in Sinatra's uri():
The regexp /[A-z]/ matches all alphabets, but also six non-alphabetic characters, as demonstrated by ("A".."z").to_a.join
=> "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz"

@rennex rennex Fix regexp to use case-insensitivity correctly
The regexp /[A-z]/ matches all alphabets, but also six non-alphabetic
characters, as demonstrated by ("A".."z").to_a.join
=> "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz"
c57cad9
@kytrinyx
Sinatra member

Good catch, thank you.

There's a failure in the integration test (test/integration_test.rb:92). Would you take a look at that?

Also, we might want a unit test to protect against regressions here. What do you think, @rkh? Too paranoid?

@rennex

The test failure from Travis seems unrelated to my changes. I copied the relevant part here, these two warnings were the cause:

lib/sinatra/base.rb:1744: warning: loading in progress, circular require considered harmful - /home/travis/.rvm/gems/ruby-1.9.2-p320/gems/rack-1.5.2/lib/rack/logger.rb
lib/sinatra/base.rb:1733: warning: loading in progress, circular require considered harmful - /home/travis/.rvm/gems/ruby-1.9.2-p320/gems/rack-1.5.2/lib/rack/nulllogger.rb

Also, the tests ran successfully on my own machine. No idea what causes those...

@vipulnsward

Warning seems unrelated to this patch.

@rkh
Sinatra member

I have no idea where this issue comes from all of a sudden.

Test would handy, indeed.

Unless I'm missing something, the main difference will be that "htt^p://foo" is treated as a relative link, correct?

@zzak zzak added the feedback label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 19, 2014
  1. @rennex

    Fix regexp to use case-insensitivity correctly

    rennex committed
    The regexp /[A-z]/ matches all alphabets, but also six non-alphabetic
    characters, as demonstrated by ("A".."z").to_a.join
    => "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz"
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/sinatra/base.rb
View
2 lib/sinatra/base.rb
@@ -262,7 +262,7 @@ def redirect(uri, *args)
# Generates the absolute URI for a given path in the app.
# Takes Rack routers and reverse proxies into account.
def uri(addr = nil, absolute = true, add_script_name = true)
- return addr if addr =~ /\A[A-z][A-z0-9\+\.\-]*:/
+ return addr if addr =~ /\A[a-z][a-z0-9\+\.\-]*:/i
uri = [host = ""]
if absolute
host << "http#{'s' if request.secure?}://"
Something went wrong with that request. Please try again.