fukamachi / quri

Yet another URI library for Common Lisp
111 stars 23 forks source link

How to handle %2F(#\/) that is not suppose to be divider #46

Closed C-Entropy closed 3 years ago

C-Entropy commented 3 years ago

Take this as an example:

(ql:quickload '(:puri :quri))

(quri:url-decode (quri:uri-path (quri:uri "http://www.franz.com/calculator/3%2f2"))) ==> "/calculator/3/2"
(puri:uri-parsed-path (puri:uri "http://www.franz.com/calculator/3%2f2")) ==> (ABSOLUTE "calculator" "3/2")

The example come from section Parsing, escape decoding/encoding and the path here

The implication of this is that to decode the URI, it must be in a parsed state. That is, you can't convert %2f (the escaped form of "/") until the path has been parsed into its component parts. Another important desire is for the application viewing the component parts to see the decoded values of the components. For example, consider:

http://www.franz.com/calculator/3%2f2

This might be the implementation of a calculator, and how someone would execute 3/2. Clearly, the application that implements this would want to see path components of "calculator" and "3/2". "3%2f2" would not be useful to the calculator application.

But, I come into this because this. So, what is the solution for this case? Thank you!

Ambrevar commented 3 years ago

Sorry, I'm not sure what the problem is or what you are asking.

(quri:uri-path (quri:uri "http://www.franz.com/calculator/3%2f2"))

correctly returns the path. From there you can split the components by / and only then decode.

Example:

 (mapcar #'quri:url-decode (str:split "/" (quri:uri-path (quri:uri "http://www.franz.com/calculator/3%2f2")) :omit-nulls t))
; => ("calculator" "3/2")

(I'm not sure if the above code is ideal, maybe quri can do this directly.)

C-Entropy commented 3 years ago

Your answer looks good to me, since I don't figure out how to achieve it directly using quri. Then should I turn to clack? Since it:

(list
...
     :path-info  (quri:url-decode (uri-path quri) :lenient t)
...
)

and so :path-info will be "/calculator/3/2" for this case. Resulting I am not able to get the ("calculator" "3/2") as I want. Thanks you! @Ambrevar

Ambrevar commented 3 years ago

Indeed, I think the problem comes from the caller.

Maybe quri could add a function like puri to return path components.

Feel free to close this if you think there is nothing left to do from the Quri side.

C-Entropy commented 3 years ago

Alright, close it.