Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #60 from jcrossley3/replace

Resolve relative to root context better
  • Loading branch information...
commit 7ab1bb67823f117c8134ece18d4bd9b3d6470684 2 parents 3ab2dde + 41ab423
James Reeves authored
Showing with 20 additions and 1 deletion.
  1. +4 −1 src/hiccup/util.clj
  2. +16 −0 test/hiccup/test/util.clj
5 src/hiccup/util.clj
View
@@ -26,7 +26,10 @@
(if (or (.getHost u)
(not (-> (.getPath u) (.startsWith "/"))))
(str u)
- (str *base-url* u)))
+ (let [base (str *base-url*)]
+ (if (.endsWith base "/")
+ (str (subs base 0 (dec (count base))) u)
+ (str base u)))))
Object
(to-str [x] (str x))
nil
16 test/hiccup/test/util.clj
View
@@ -30,6 +30,22 @@
(is (= (to-str (to-uri "https://example.com/bar")) "https://example.com/bar"))
(is (= (to-str (to-uri "bar")) "bar"))
(is (= (to-str (to-uri "../bar")) "../bar"))
+ (is (= (to-str (to-uri "//example.com/bar")) "//example.com/bar"))))
+ (testing "with base URL for root context"
+ (with-base-url "/"
+ (is (= (to-str (to-uri "/bar")) "/bar"))
+ (is (= (to-str (to-uri "http://example.com")) "http://example.com"))
+ (is (= (to-str (to-uri "https://example.com/bar")) "https://example.com/bar"))
+ (is (= (to-str (to-uri "bar")) "bar"))
+ (is (= (to-str (to-uri "../bar")) "../bar"))
+ (is (= (to-str (to-uri "//example.com/bar")) "//example.com/bar"))))
+ (testing "with base URL containing trailing slash"
+ (with-base-url "/foo/"
+ (is (= (to-str (to-uri "/bar")) "/foo/bar"))
+ (is (= (to-str (to-uri "http://example.com")) "http://example.com"))
+ (is (= (to-str (to-uri "https://example.com/bar")) "https://example.com/bar"))
+ (is (= (to-str (to-uri "bar")) "bar"))
+ (is (= (to-str (to-uri "../bar")) "../bar"))
(is (= (to-str (to-uri "//example.com/bar")) "//example.com/bar")))))
(deftest test-url-encode
Please sign in to comment.
Something went wrong with that request. Please try again.