Skip to content

Commit

Permalink
Handle strings and byte vectors in query values, and nothing else.
Browse files Browse the repository at this point in the history
When encoding query values, don't try to convert a value to a string when we
don't know what else to do with it: handle strings and byte vectors, and error
out on anything else.

Fixes #30.
  • Loading branch information
jathd committed Feb 15, 2021
1 parent 4138c94 commit 6ced0b4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Expand Up @@ -64,7 +64,7 @@ Create a `uri` object.
;=> #<QURI.URI.HTTP:URI-HTTP http://8arrow.org/>
(make-uri :defaults "http://8arrow.org"
:query '(("guest" . 1)))
:query '(("guest" . "1")))
;=> #<QURI.URI.HTTP:URI-HTTP http://8arrow.org?guest=1>
```

Expand Down
9 changes: 5 additions & 4 deletions src/encode.lisp
Expand Up @@ -97,9 +97,10 @@
(write-string (url-encode field :encoding encoding :space-to-plus space-to-plus) s)
(when value
(write-char #\= s)
(write-string (url-encode (if (stringp value)
value
(write-to-string value))
:encoding encoding :space-to-plus space-to-plus) s))
(check-type value (or string simple-byte-vector))
(write-string (url-encode value
:encoding encoding
:space-to-plus space-to-plus)
s))
(when rest
(write-char #\& s)))))
6 changes: 5 additions & 1 deletion t/encode.lisp
Expand Up @@ -17,6 +17,10 @@

(subtest "url-encode-params"
(is (url-encode-params '(("a" . "b") ("c" . "d")))
"a=b&c=d"))
"a=b&c=d")
(is (url-encode-params
`(("a" . ,(make-array 1 :element-type '(unsigned-byte 8)
:initial-contents (list (char-code #\b))))))
"a=b"))

(finalize)

0 comments on commit 6ced0b4

Please sign in to comment.