URL normalization :- http://en.wikipedia.org/wiki/URL_normalization - I just read this source. I found a method uri#normalization : http://www.ruby-doc.org/stdlib-2.0/libdoc/uri/rdoc/URI/Generic.html#method-i-normalize-21 But not able to figure out how this method works: require ''uri'' uri = URI.parse("http://www.example.com/../a/b/../c/./d.html") p uri.normalize.to_s #=> "http://www.example.com/../a/b/../c/./d.html" But I expect " http://www.example.com/a/c/d.html" Nothing any thing change encountered. So any one out there have any good example to understand this method? Thanks -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c134dadaa651c05945f2091d843630dd%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
On Saturday, 25 May 2013 07:58:06 UTC-4, Ruby-Forum.com User wrote:> > URL normalization :- http://en.wikipedia.org/wiki/URL_normalization - I > just read this source. > > I found a method uri#normalization : > > http://www.ruby-doc.org/stdlib-2.0/libdoc/uri/rdoc/URI/Generic.html#method-i-normalize-21 > > But not able to figure out how this method works: > > require ''uri'' > > uri = URI.parse("http://www.example.com/../a/b/../c/./d.html") > p uri.normalize.to_s > #=> "http://www.example.com/../a/b/../c/./d.html" > But I expect " http://www.example.com/a/c/d.html" > > Nothing any thing change encountered. So any one out there have any good > example to understand this method? > >Quickest way is to read the source (available from the ''click to toggle source'' link you get when hovering over a method): def normalize! if path && path == '''' set_path(''/'') end if scheme && scheme != scheme.downcase set_scheme(self.scheme.downcase) end if host && host != host.downcase set_host(self.host.downcase) end end looks like the idea is to handle the following oddly-formatted sorts of URIs: http://example.com (no trailing /) HttP://example.com/ (protocol capitalized oddly) http://EXAMPLE.com/ (host capitalized) If your goal is to normalize out those ..s in your path, File.expand_path may be more what you''re looking for: File.expand_path(''/no/such/path/../srsly'') # => returns "/no/such/srsly" But really, including .. in a URI isn''t entirely valid - not all structures exposed via URI are filesystems, after all... --Matt Jones -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/aa43d485-64b7-4c3f-92ff-c39aa8587e68%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Matt Jones wrote in post #1110185:> Quickest way is to read the source (available from the ''click to toggle > source'' link you get when hovering over a method):> def normalize! > if path && path == '''' > set_path(''/'') > end > if scheme && scheme != scheme.downcase > set_scheme(self.scheme.downcase) > end > if host && host != host.downcase > set_host(self.host.downcase) > end > end> looks like the idea is to handle the following oddly-formatted sorts of > URIs: > > http://example.com (no trailing /) > HttP://example.com/ (protocol capitalized oddly) > http://EXAMPLE.com/ (host capitalized)Thanks @matt! I am happy to see this. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5e3f990a0dedce1d7605b1ac9a6cc022%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.