Permalink
Browse files

Make sure protocol-of does not fail when input has no protocol (scheme)

  • Loading branch information...
1 parent 2e7e73b commit c7f7af52b003ea4ebf8d05f5d7e67c3f7573135d @michaelklishin committed Mar 27, 2012
Showing with 13 additions and 5 deletions.
  1. +5 −0 ChangeLog.md
  2. +4 −3 src/clojure/clojurewerkz/urly/core.clj
  3. +4 −2 test/clojurewerkz/urly/test/core.clj
View
@@ -1,3 +1,8 @@
+## Changes between Urly 1.0.0-beta6 and 1.0.0-beta7
+
+`urly.core/protocol-of` how correctly returns nil for inputs that have no protocol
+
+
## Changes between Urly 1.0.0-beta5 and 1.0.0-beta6
`urly.core/absolute?` and `urly.core/relative?` now work for `urly.UrlLike` instances
@@ -47,7 +47,8 @@
(extend-protocol PartsAccessors
URI
(protocol-of [^URI input]
- (-> input .getScheme .toLowerCase))
+ (when-let [s (.getScheme input)]
+ (.toLowerCase s)))
(host-of [^URI input]
(-> input .getHost .toLowerCase))
(port-of [^URI input]
@@ -66,9 +67,9 @@
URL
(protocol-of [^URL input]
- (-> input .getProtocol .toLowerCase))
+ (protocol-of (.toURI input)))
(host-of [^URL input]
- (-> input .getHost .toLowerCase))
+ (host-of (.toURI input)))
(port-of [^URL input]
(.getPort input))
(user-info-of [^URL input]
@@ -41,6 +41,8 @@
(is (= "http" (protocol-of (URI. "http://clojure.org"))))
(is (= "https" (protocol-of (URL. "htTPS://Www.clojure.org"))))
(is (= "http" (protocol-of "http://clojure.org")))
+ (is (nil? (protocol-of "clojure.org")))
+ (is (nil? (protocol-of "/Protocols")))
(is (= "https" (protocol-of "HTTPS://CLOJURE.org"))))
(deftest test-host-of
@@ -140,7 +142,7 @@
(is (= "/iphone" (.getPath url-like)))
(is (= (.getPath uri) (.getFile url-like)))))
-(deftest ^{ :focus true } test-instantiating-url-like-from-domain-name
+(deftest test-instantiating-url-like-from-domain-name
(let [uri "arstechnica.com"
url-like (UrlLike/homepageOf uri)
host "arstechnica.com"]
@@ -150,7 +152,7 @@
(is (= host (.getHost url-like)))
(is (= "/" (.getPath url-like)))))
-(deftest ^{ :focus true } test-instantiating-url-like-from-domain-name-and-protocol
+(deftest test-instantiating-url-like-from-domain-name-and-protocol
(let [uri "github.com"
url-like (UrlLike/homepageOf uri "https")
host "github.com"]

0 comments on commit c7f7af5

Please sign in to comment.