okfn/ckan — pull request #412 by tobes (2013-02-18 09:43:24+00:00)
Title: Data Hub: Automatic prepending of http:// to resource URLs breaks FTP and Git URLs

On the Data Hub, when a resource is edited and saved, and the URL of the resource does *not* start with `http://`, then `http://` is automatically prepended before the URL is saved. This is probably done so that `www.myserver.com/myresource` is automatically turned into `http://www.myserver.com/myresource`. But it breaks URLs that use any protocol other than HTTP, for example FTP or Git. As a result, URLs like this are common on the Data Hub:

* http://ftp://ftp.uniprot.org/pub/databases/uniprot/current_release/rdf/
* http://git://eculture.cs.vu.nl/home/git/econnect/metadata/AHM.git

The solution is to check for the presence of a *scheme* in the URL, not simply for the presence of `http`. The following regex matches any valid scheme according to RFC 3986:

````
^[a-zA-Z][a-zA-Z0-9+.-]*:
````

If it doesn't match, then prepending `http://` is probably reasonable. Otherwise, it is most definitely not.