on URI Ruby escaping

February 3, 2009 by pedro mota

URI.escape method with no options doesn’t provide a trully good escape, and i just noticed it upon the need to access an API.\n\nurl = 'http://www.ruby-lang.org'\nbad = URI.escape(url)\ngood = URI.escape(url, Regexp.new(\"[^#{URI::PATTERN::UNRESERVED}]\"))\n\nThe difference is:\n\nbad => \"http://www.ruby-lang.org\"\ngood => \"http%3A%2F%2Fwww.ruby-lang.org\"\n\n\n(via snippets.dzone => Matt Zukowski)

© 2018 | Follow on Twitter | pedro mg & Hugo