weavejester / hiccup

Fast library for rendering HTML in Clojure
http://weavejester.github.io/hiccup
Eclipse Public License 1.0
2.68k stars 175 forks source link

hiccup does not handle URLs without protocol correctly in include-js #56

Closed yogthos closed 12 years ago

yogthos commented 12 years ago

When deploying with a context root if a url does not specify a protoco then it will be treated as a relative URL:

(include-js  "//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js")
[:script {:type "text/javascript", :src #<URI //ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js>}]
weavejester commented 12 years ago

Your example doesn't show it being treated as a relative URL (a URI can be relative or absolute). However, when used with with-base-url, there is a problem:

user> (with-base-url "/foo" (html (include-js "//bar.com/baz")))
"<script src=\"/foo//bar.com/baz\" type=\"text/javascript\"></script>"

This is because a schemaless URL is not considered to be absolute by Java (which makes sense, now that I think about it), and Hiccup is designed to append the base URL to any relative URL that starts with a slash.

I'll fix this issue and release 1.0.1.

yogthos commented 12 years ago

great thanks!