[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: URI.escape() broken or misdocumented in Ruby 1.8.4?

Austin Ziegler

7/7/2006 2:57:00 PM

On 7/6/06, Andrew Hodgkinson <ahodgkin@rowing.org.uk> wrote:
> I posted this in the Ruby On Rails forum a moment ago because of other
> URI.escape() related messages there, but really it's a Ruby thing, not a
> Rails thing, so it belongs in the Ruby forum. Thus, a repost :-)

I don't have a clear answer to your question, below, but a couple of
points that *MUST* be made: You are not posting to a forum with
*either* the "Ruby on Rails 'forum'" or the "Ruby 'forum'". You are
posting to a mailing list gateway. You are correct that this probably
belongs on ruby-talk (the mailing list to which your post has been
gatewayed) and comp.lang.ruby (the newsgroup to which the mailing list
is bidirectionally gatewayed). But it's not a forum.

It does appear to be a documentation bug or a code bug that was
introduced; someone else will have to verify that.

> I was going to update the documentation Wiki to mention the differing
> behaviour in Ruby 1.8.4 by clicking on the link given at the bottom of
> the page, which goes to:
>
> http://www.ruby-doc.org/ru/wiki/index.rb/Core/U...

I didn't even know about this ;)

I suspect that it's not filled because it's not how the documentation
is dealt with in Ruby.

Lastly, your example:

p URI.escape("@?@!", Regexp.new("[!?]"))
# => "@%3F@%21"

Can be rewritten as:

p URI.escape("@?@!", /[!?]/)

You don't need Regexp.new.

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca

2 Answers

Yohanes Santoso

7/7/2006 3:15:00 PM

0

"Austin Ziegler" <halostatue@gmail.com> writes:

> It does appear to be a documentation bug or a code bug that was
> introduced; someone else will have to verify that.


This seems like a documentation bug. The second argument is used as-is
in calling String#gsub which matches whole-string when given a string
argument.

Note that the documentation in 1.8.4's uri library code is correct.


YS.

mathew

7/14/2006 6:43:00 PM

0

Austin Ziegler wrote:
> On 7/6/06, Andrew Hodgkinson <ahodgkin@rowing.org.uk> wrote:
>> I was going to update the documentation Wiki to mention the differing
>> behaviour in Ruby 1.8.4 by clicking on the link given at the bottom of
>> the page, which goes to:
>>
>> http://www.ruby-doc.org/ru/wiki/index.rb/Core/U...
>
> I didn't even know about this ;)

Me neither, and I wrote the most recent updates for the documentation
for the URI class...

It seems to be a blank page now, though.

Yohanes Santoso wrote:
> This seems like a documentation bug. The second argument is used as-is
> in calling String#gsub which matches whole-string when given a string
> argument.

I disagree. The code in 1.8.4 turns a string second argument into a
RegExp before calling gsub with it.

def escape(str, unsafe = UNSAFE)
unless unsafe.kind_of?(Regexp)
# perhaps unsafe is String object
unsafe = Regexp.new(Regexp.quote(unsafe), false, 'N')
end

So it seems clear to me that it's supposed to be doing something other
than matching a String second argument as-is. So my vote's for it being
supposed to do what the documentation says.

I see that someone has fixed the bug in CVS head, anyhow. Code now
matches the documented behavior, which is more useful.


mathew
--
<URL:http://www.pobox.com/...
My parents went to the lost kingdom of Hyrule
and all I got was this lousy triforce.