From 65846fb5baa944ed4967e0af158c03bc96481f35 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Tue, 11 Mar 2014 20:20:23 -0700 Subject: [PATCH] Revert "urls: Allow URLs of the form //foo.com, which take on the protocol of the URL they derive from." This reverts commit e6598fc22fd91309288fbe9840f7872d8fd84438. --- basis/urls/urls-tests.factor | 9 +-------- basis/urls/urls.factor | 21 +++++---------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/basis/urls/urls-tests.factor b/basis/urls/urls-tests.factor index e196161e9b..e188a1c645 100644 --- a/basis/urls/urls-tests.factor +++ b/basis/urls/urls-tests.factor @@ -225,13 +225,6 @@ urls [ derive-url ] unit-test -! Support //foo.com, which has the same protocol as the url we derive from -[ URL" http://foo.com" ] -[ URL" http://google.com" URL" //foo.com" derive-url ] unit-test - -[ URL" https://foo.com" ] -[ URL" https://google.com" URL" //foo.com" derive-url ] unit-test - [ "a" ] [ "a" "b" set-query-param "b" query-param ] unit-test @@ -264,4 +257,4 @@ urls [ [ "/" ] [ "http://www.jedit.org" >url path>> ] unit-test -[ "USING: urls ;\nURL\" foo\"" ] [ URL" foo" unparse-use ] unit-test +[ "USING: urls ;\nURL\" foo\"" ] [ URL" foo" unparse-use ] unit-test \ No newline at end of file diff --git a/basis/urls/urls.factor b/basis/urls/urls.factor index 2e1f980806..66e6ee01eb 100644 --- a/basis/urls/urls.factor +++ b/basis/urls/urls.factor @@ -57,8 +57,7 @@ hostname-spec = hostname ("/"|!(.)) => [[ first ]] auth = (username (":" password => [[ second ]])? "@" => [[ first2 2array ]])? -url = (((protocol "://") => [[ first ]] auth hostname) - | (("//") => [[ f ]] auth hostname))? +url = ((protocol "://") => [[ first ]] auth hostname)? (pathname)? ("?" query => [[ second ]])? ("#" anchor => [[ second ]])? @@ -107,7 +106,9 @@ M: pathname >url string>> >url ; [ port>> ] [ port>> ] [ protocol>> protocol-port ] tri = [ drop f ] when ; -: unparse-host-part ( url -- ) +: unparse-host-part ( url protocol -- ) + % + "://" % { [ unparse-username-password ] [ host>> url-encode % ] @@ -115,22 +116,10 @@ M: pathname >url string>> >url ; [ path>> "/" head? [ "/" % ] unless ] } cleave ; -! URL" //foo.com" takes on the protocol of the url it's derived from -: unparse-protocol ( url -- ) - dup protocol>> [ - % "://" % unparse-host-part - ] [ - dup host>> [ - "//" % unparse-host-part - ] [ - drop - ] if - ] if* ; - M: url present [ { - [ unparse-protocol ] + [ dup protocol>> dup [ unparse-host-part ] [ 2drop ] if ] [ path>> url-encode % ] [ query>> dup assoc-empty? [ drop ] [ "?" % assoc>query % ] if ] [ anchor>> [ "#" % present url-encode % ] when* ]