Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape slash in URL parameter

Tags:

javascript

php

$.ajax({
        url: "/api/v1/cases/annotations/" + case_id + "/" + encodeURIComponent(current_plink),

I am using encodeURIComponent to escape slash. But it does not work for me. This code convert "slash" to "%2F" but apache does not recognize it.

My php part like this :

$app->get('/cases/annotations/:case_id/:prep_name', 'authenticatePathologist', function($case_id, $prep_name) use ($app) {

If i try to send parameter which include slash, it returns page not found. enter image description here

But if i try to send parameter which does not include slash, it returns OK. enter image description here

like image 907
Levent Tulun Avatar asked Dec 05 '22 18:12

Levent Tulun


1 Answers

You should encode it twice with encodeURIComponent, i.e. encodeURIComponent(encodeURIComponent(current_plink)). If you encode it only once, the server decodes it, and it's the same as not encoding it at all.

like image 54
Michał Perłakowski Avatar answered Dec 09 '22 14:12

Michał Perłakowski