I'm playing around with Sinatra, and I would like to make one of my routes case insensitive. I tried adding the route like this:
get "(?i)/tileflood/?" do
end
But it doesn't match any permutation of /tileflood as expected. I tested the following regex on rubular.com, and it matches just fine. Am I missing something?
\/(?i)tileflood\/?
You want a real regexp for your route:
require 'sinatra'
get %r{^/tileflood/?$}i do
request.url + "\n"
end
Proof:
smagic:~ phrogz$ curl http://localhost:4567/tileflood
http://localhost:4567/tileflood
smagic:~ phrogz$ curl http://localhost:4567/tIlEflOOd
http://localhost:4567/tIlEflOOd
smagic:~ phrogz$ curl http://localhost:4567/TILEFLOOD/
http://localhost:4567/TILEFLOOD/
smagic:~ phrogz$ curl http://localhost:4567/TILEFLOOD/z
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { text-align:center;font-family:helvetica,arial;font-size:22px;
color:#888;margin:20px}
#c {margin:0 auto;width:500px;text-align:left}
</style>
</head>
<body>
<h2>Sinatra doesn't know this ditty.</h2>
<img src='/__sinatra__/404.png'>
<div id="c">
Try this:
<pre>get '/TILEFLOOD/z' do
"Hello World"
end</pre>
</div>
</body>
</html>
smagic:~ phrogz$ curl http://localhost:4567/tileflaad
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { text-align:center;font-family:helvetica,arial;font-size:22px;
color:#888;margin:20px}
#c {margin:0 auto;width:500px;text-align:left}
</style>
</head>
<body>
<h2>Sinatra doesn't know this ditty.</h2>
<img src='/__sinatra__/404.png'>
<div id="c">
Try this:
<pre>get '/tileflaad' do
"Hello World"
end</pre>
</div>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With