2012-07-02 61 views
3

我有一個包含一個轉義URL字符串:URL解碼字符串

http%3A%2F%2Fexample.com%3Ffoo%3Dbar+baz 

我試圖將其解碼爲以下:但是

http://example.com?foo=bar+baz 

,我可以沒有找到Drakma出口的任何適合的功能。我可以連接代碼如下所示:

* url-string 

"http://example.com?foo=bar+baz" 
* (drakma:url-encode url-string :utf-8) 

"http%3A%2F%2Fexample.com%3Ffoo%3Dbar%2Bbaz" 

...所以我想我是在正確的軌道上。如果任何人都可以向正確的方向提供幫助,我會很感激:-)我使用SBCL 1.0.54,它是從64位Linux Mint 13上的源代碼構建而成的。

如果它有助於說明我是什麼試圖做,在Ruby中,我會做以下事情:

> uri_string = "http%3A%2F%2Fexample.com%3Ffoo%3Dbar+baz" 
=> "http%3A%2F%2Fexample.com%3Ffoo%3Dbar+baz" 
> URI.decode uri_string 
=> "http://example.com?foo=bar+baz" 
+0

如果您想知道,我知道這絕對是因爲_entire_網址被轉義了,包括協議規範。我正在爲澳大利亞在線音樂商店編寫一個跨平臺的下載客戶端,該商店提供的文件中包含上述示例中完全轉義的URL列表。 –

+1

只是問明顯:(apropos「DECODE」)不顯示任何有趣的功能? (apropos「DECODE」「DRAKMA」)? –

回答

11

快速SLIME會話。

CL-USER> (ql-dist:system-apropos "url") 

#<SYSTEM curly/curly-20120407-git/quicklisp 2012-05-20> 
#<SYSTEM curly.test/curly-20120407-git/quicklisp 2012-05-20> 
#<SYSTEM do-urlencode/do-urlencode-20120407-git/quicklisp 2012-05-20> 
#<SYSTEM url-rewrite/url-rewrite-0.1.1/quicklisp 2012-05-20> 

CL-USER> (ql:quickload :do-urlencode) 

抄送pdo-urlencodeRET

DO-URLENCODE:URLDECODE 
    Function: (not documented) 
DO-URLENCODE:URLENCODE 
    Function: (not documented) 
DO-URLENCODE:URLENCODE-MALFORMED-STRING 
    Type: (not documented) 
DO-URLENCODE:URLENCODE-MALFORMED-STRING-STRING 
    Generic Function: (not documented) 

CL-USER> (do-urlencode:urldecode "http%3A%2F%2Fexample.com%3Ffoo%3Dbar%2Bbaz") 

"http://example.com?foo=bar+baz" 
+0

感謝:-)我仍然在學習'Lisp方式'的做法......它甚至從來沒有想過有可能從REPL獲得有關Quicklisp包的幫助。 –

0

實測另一種解決方案,具有Quri,一個URI處理與編碼和解碼實用程序(uri和參數)庫:

(url-decode "http%3A%2F%2Fexample.com%3Ffoo%3Dbar%2Bbaz") 
;; "http://example.com?foo=bar+baz" 

(ql:quickload :quri)安裝,然後選件(use-package :quri)

(我的來源:lisp-lang.org's recommend librariesawesone-cl)。