I''m wondering why URI.encode does not encode &=? URI.encode(''&=?'') => ''&=?'' Is there alternative that works better? or should I write my own? -reynard --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
There''s an optional second arg to specify chars to replace: http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/Escape.html#M009245 b Reynard wrote:> I''m wondering why URI.encode does not encode &=? > URI.encode(''&=?'') > => ''&=?'' > > Is there alternative that works better? or should I write my own? > > -reynard > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
What''s the second argument supposed to be though? should I create a regexp from scratch or use a pre-defined one? the documentation is not very clear.>From googling I found that some people say URI.encode is buggy andsuggested to use CGI.escape? seems to work for me. - reynard On Apr 30, 10:06 pm, Ben Munat <bmu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> There''s an optional second arg to specify chars to replace: > > http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/Escape.htm... > > b > > Reynard wrote: > > I''m wondering whyURI.encodedoes not encode &=? > >URI.encode(''&=?'') > > => ''&=?'' > > > Is there alternative that works better? or should I write my own? > > > -reynard--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
After I sent that I got curious... I found that the second arg is just a regex with the chars to escape... so /[&=?]/ would escape the chars you''re worried about. I also found however, that it *only* escapes the chars in the regex if you provide one... so you''ll have to make sure to escape the stuff that would have been escaped. I also figured out that the REGEXP::UNSAFE constant they mention is actually URI::REGEXP::UNSAFE. If you require ''uri'' in irb and then type that, it''ll dump the chars that are in the default regex: /[^-_.!~*''()a-zA-Z\d;\/?:@&=+$,\[\]]/n And, one more thing: the file that this is defined in should be at RUBY_ROOT/uri/common.rb... and there are a lot of regexes defined in there. b Reynard wrote:> What''s the second argument supposed to be though? > should I create a regexp from scratch or use a pre-defined one? the > documentation is not very clear. >>From googling I found that some people say URI.encode is buggy and > suggested to use CGI.escape? > seems to work for me. > > - reynard > > On Apr 30, 10:06 pm, Ben Munat <bmu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> There''s an optional second arg to specify chars to replace: >> >> http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/Escape.htm... >> >> b >> >> Reynard wrote: >>> I''m wondering whyURI.encodedoes not encode &=? >>> URI.encode(''&=?'') >>> => ''&=?'' >>> Is there alternative that works better? or should I write my own? >>> -reynard > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---