singlebrook / utf8-cleaner

MIT License
277 stars 44 forks source link

Params merged if there is invalid encoding #39

Closed ksdputra closed 3 years ago

ksdputra commented 3 years ago

Hi, I am start using this gem because it is the most easy solution to remove Invalid % encoding error. But I ran into a problem.

So when I hit with these:

# 1
url?page=1&perPage=5&query=alcohol 70%

# 2
url?page=1&perPage=5&query=alcohol 70

Both the params in controller would be:

<ActionController::Parameters {"page=1", "perPage"=>"5", "query"=>"alcohol 70", "controller"=>"api/v1/search_context", "action"=>"index", "search_context"=>{}} permitted: false>

But when I move the query params to right after url, these are what I got:

# 1 (This is work just fine)
url?query=alcohol 70&page=1&perPage=5
<ActionController::Parameters {"query"=>"alcohol 70", "page=1", "perPage"=>"5", "controller"=>"api/v1/search_context", "action"=>"index", "search_context"=>{}} permitted: false>

# 2 (The query value get merged with key page)
url?query=alcohol 70%&page=1&perPage=5
<ActionController::Parameters {"query"=>"alcohol 70page=1", "perPage"=>"5", "controller"=>"api/v1/search_context", "action"=>"index", "search_context"=>{}} permitted: false>

Is there a way to make it works unless 'just change the params order'?

Thank you in advance.

sbleon commented 3 years ago

Having a bare (unencoded) % in a URL is not valid, per the URL RFC ( https://tools.ietf.org/html/rfc1738). The space character also needs to be encoded. So, your query variable needs to look like query=alcohol%2070%25 in order to be processed correctly. The %20 is the encoded space character and the %25 is the encoded % character.

On Wed, Mar 17, 2021 at 8:11 AM KSD Putra @.***> wrote:

Hi, I am start using this gem because it is the most easy solution to remove Invalid % encoding error. But I ran into a problem.

So when I hit with these:

1

url?page=1&perPage=5&query=alcohol 70%

2

url?page=1&perPage=5&query=alcohol 70

Both the params in controller would be:

<ActionController::Parameters {"page=1", "perPage"=>"5", "query"=>"alcohol 70", "controller"=>"api/v1/search_context", "action"=>"index", "search_context"=>{}} permitted: false>

But when I move the query params to right after url, these are what I got:

1 (This is work just fine)

url?query=alcohol 70&page=1&perPage=5 <ActionController::Parameters {"query"=>"alcohol 70", "page=1", "perPage"=>"5", "controller"=>"api/v1/search_context", "action"=>"index", "search_context"=>{}} permitted: false>

2 (The query value get merged with key page)

url?query=alcohol 70%&page=1&perPage=5 <ActionController::Parameters {"query"=>"alcohol 70page=1", "perPage"=>"5", "controller"=>"api/v1/search_context", "action"=>"index", "search_context"=>{}} permitted: false>

Is there a way to make it works unless 'just change the params order'?

Thank you in advance.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/singlebrook/utf8-cleaner/issues/39, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABQQN6I5QWZH5STUSLLDRLTECL5HANCNFSM4ZKO3Y4Q .