如何使drakma处理URL中的非拉丁1字符



我遇到了一个错误,使用sbcl在给定的url中使用非拉丁1字符,例如:

(drakma:http-request "http://www.youtube.com/„weird-url")
debugger invoked on a FLEXI-STREAMS:EXTERNAL-FORMAT-ENCODING-ERROR in thread
#<THREAD "initial thread" RUNNING {1002998D23}>:
  #DOUBLE_LOW-9_QUOTATION_MARK (code 8222) is not a LATIN-1 character.
Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.
(FLEXI-STREAMS::SIGNAL-ENCODING-ERROR
 #<FLEXI-STREAMS::FLEXI-LATIN-1-FORMAT (:ISO-8859-1 :EOL-STYLE :LF)
   {1002F196E3}>
 "~S (code ~A) is not a LATIN-1 character."
 #DOUBLE_LOW-9_QUOTATION_MARK
 8222)

显然标头被定义为由RFC2616以Latin-1发送(这是我在遇到此错误后在github上打开的票),因此URL必须在传递给drakma之前进行正确编码。但我不知道怎么做,因为显然这是不可能的(因为它不是拉丁-1字符)。

对于我的示例,什么是工作调用(除了URL是虚假的并且可以缩短为http://www.youtube.com的事实之外)?

(drakma:http-request (magic-encoding-function "http://www.youtube.com/„weird-url"))

这个问题与DRAKMA无关。这是PURI的错。我使用我的PURI分支:https://github.com/archimag/puri-unicode.

刚刚发现,如果缺陷存在于新实例化对象的后处理中,那么解决方法可能是将该过程分成两部分:

  1. 只构造Latin-1部分的URI
  2. 设置路径

就像:

(let ((uri (puri:uri "https://wikimedia.org"))) (setf (puri:uri-path uri) (concatenate 'string "/" (drakma:url-encode "/кадабра" :utf-8))) uri) 生产:

#<PURI:URI https://wikimedia.org/%D0%BA%D0%B0%D0%B4%D0%B0%D0%B1%D1%80%D0%B0>

Drakma然后接受这个URI而不做任何额外的处理。

最新更新