floats in url

66 views
Skip to first unread message

Joel VanderWerf

unread,
Jun 8, 2008, 2:02:12 PM6/8/08
to sina...@googlegroups.com

Hi, all,

Sinatra was not recognizing a url with a floating point number in it, like

/foo/bar/1.23

This is because Event#initialize uses URI_CHAR = '[^/?:,&#\.]' to build
the pattern to match uri params.

I can monkey-patch around this easily, but what's the right way to
accept params with decimal points?

Also, I'd like to allow commas (which are currently rejected for the
same reason), as in:

/foo/bar/1.23,4.56

Is there any reason not to allow this syntax? It's used for example in
google map urls.

Thanks, and thanks for Sinatra!

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Blake Mizerany

unread,
Jun 8, 2008, 5:58:16 PM6/8/08
to sina...@googlegroups.com
Joel,

I've been monkey patching my apps that need the ability to accept characters such as dot and comma.

Here is my hack from an app that's a mod_rewrite replacement and needed to accepts dots in paths:


configure do
  #####
# WARNING! SUPER HACK
# Allow dots in path param values
Sinatra::Event.send(:remove_const, "URI_CHAR")
Sinatra::Event.const_set("URI_CHAR", '[^/?:,&#]')
end

I'll consider taken it out or creating an option to turn on loose matching for these chars.

-Blake
--
Blake Mizerany
blake.m...@gmail.com

Joel VanderWerf

unread,
Jun 10, 2008, 1:16:06 PM6/10/08
to sina...@googlegroups.com

Any suggestions?

Also, what about '?' in urls? Shouldn't sinatra support that?

Blake Mizerany

unread,
Jun 10, 2008, 3:03:03 PM6/10/08
to sina...@googlegroups.com
Sinatra goes support '?'.   Use `params`.  If you need the path use `request.path_info`.

There is much more there. Please see Rack::Request (http://rack.rubyforge.org/doc/classes/Rack/Request.html)

Sinatra install request.user_agent convince as well.

-Blake
--
Blake Mizerany
blake.m...@gmail.com

Joel VanderWerf

unread,
Jun 10, 2008, 3:40:25 PM6/10/08
to sina...@googlegroups.com

Got it now, thanks, Blake.

I did not realize that

get '/test/*' do...end

will not only process cgi params and put them in +params+, but will also
handle decimal points in the values of the params.

Very nice!

> blake.m...@gmail.com <mailto:blake.m...@gmail.com>

Ryan Tomayko

unread,
Jun 10, 2008, 3:41:37 PM6/10/08
to sina...@googlegroups.com
Blake Mizerany wrote:
> Sinatra goes support '?'. Use `params`. If you need the path use
> `request.path_info`.
>
> There is much more there. Please see Rack::Request
> (http://rack.rubyforge.org/doc/classes/Rack/Request.html)
>
> Sinatra install request.user_agent convince as well.

It may be interesting to note that Blake is actually a native English
speaker. :)

What's sad is that I understood what you were trying to say there.

--
Ryan Tomayko <http://tomayko.com/>

Blake Mizerany

unread,
Jun 10, 2008, 3:42:44 PM6/10/08
to sina...@googlegroups.com
;)  you can get that value via `params[:splat] #=> [value]`
--
Blake Mizerany
blake.m...@gmail.com

Blake Mizerany

unread,
Jun 10, 2008, 3:46:23 PM6/10/08
to sina...@googlegroups.com
I'm bad. I know.  I admit it all the time.  It's the programmer in me.  English is my second language, code is first. ;)
--
Blake Mizerany
blake.m...@gmail.com

Joel VanderWerf

unread,
Jun 15, 2008, 1:16:46 PM6/15/08
to Blake Mizerany, sina...@googlegroups.com

All I need is dots in the cgi params (which works perfectly with
sinatra), not in the rest of the path. I'm trying to think if any kind
of GIS query would need otherwise, but nothing stands out.

Btw: my app is a prototype for in-vehicle queries of roadway data
(signage, traffic conditions, etc.) that can be overlaid on a map or
used for audible alerts. [http://www.dot.gov/affairs/rita0107.htm]

> blake.m...@gmail.com <mailto:blake.m...@gmail.com>

Reply all
Reply to author
Forward
0 new messages