1
0
Fork 0

- [gemini] allow percent encoding of query, path and fragment only if not already encoded.

This commit is contained in:
cage 2020-12-28 12:40:47 +01:00
parent 6c590dbf1a
commit 5151fbe4a2
3 changed files with 25 additions and 8 deletions

View File

@ -287,19 +287,15 @@
(defun percent-encode-path (path) (defun percent-encode-path (path)
(let ((splitted (split "/" path))) (let ((splitted (split "/" path)))
(if splitted (if splitted
(reduce (lambda (a b) (strcat a "/" (percent-encode b))) (reduce (lambda (a b) (strcat a "/" (maybe-percent-encode b)))
splitted) splitted)
path))) path)))
(defun percent-encode-allow-null (data)
(when data
(percent-encode data)))
(defun percent-encode-query (query) (defun percent-encode-query (query)
(percent-encode-allow-null query)) (maybe-percent-encode query))
(defun percent-encode-fragment (fragment) (defun percent-encode-fragment (fragment)
(percent-encode-allow-null fragment)) (maybe-percent-encode fragment))
(defun request (host path &key (defun request (host path &key
(query nil) (query nil)

View File

@ -371,7 +371,10 @@
:annotated-text-value :annotated-text-value
:box-fit-multiple-column-annotated :box-fit-multiple-column-annotated
:collect-links :collect-links
:percent-encode)) :percent-encode
:percent-decode
:percent-encoded-p
:maybe-percent-encode))
(defpackage :html-utils (defpackage :html-utils
(:use (:use

View File

@ -673,3 +673,21 @@ printed in the box column by column; in the example above the results are:
(defun percent-encode (string) (defun percent-encode (string)
(percent-encoding:encode string :encoding :utf-8)) (percent-encoding:encode string :encoding :utf-8))
(defun percent-decode (string)
(percent-encoding:decode string :encoding :utf-8))
(defun percent-encoded-p (string)
(conditions:with-default-on-error (t)
(string/= string
(percent-decode string))))
(defun percent-encode-allow-null (data)
(when data
(percent-encode data)))
(defun maybe-percent-encode (data)
"Note that when data is null this function returns nil"
(if (percent-encoded-p data)
data
(percent-encode-allow-null data)))