Multiplay Labs

tech hits and tips from Multiplay

Archive for July 2nd, 2009

Ruby URI.parse being strict results in URI::InvalidURIError

without comments

When using ruby’s URI.parse yesterday I was getting URI::InvalidURIError on what seemed to be a perfectly valid URI. After much digging in the source and reading the URI RFC 2396¬†and subsequent 3986, I discovered that the reason for this is that URI.parse applies this RFC strictly, so where a number of applications are quite happy to provide and use URI’s containing the “unwise” characters, URI.parse doesn’t accept them and throws a URI::InvalidError.

Fear not though there’s a really easy fix, just replace the direct call with:

myuri = URI.parse( URI.encode( uri_string ) )

This does however raise the question: Should parse implicitly call encode?

Written by Dilbert

July 2nd, 2009 at 8:36 am

Posted in Code