Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

%2F instead of slash in url?

I have a problem with jquery syntax in an url link:

this is the link i am getting (englisch):

...myaccount/?lang=en%2Fprint-order%2F2067%2F&print-order-type=receipt

this is the german link:

...myaccount/print-order/2067/?print-order-type=receipt

the problem now is, that the link looks ok in my browser

myaccount/print-order/2067/?print-order-type=receipt

but actually there's always a "%2F" instead of a "/" inside the link when I copy it which leads to the problem of getting an 404.

When I manually replace "%2F" the link works.

Where is the problem? Any idea to fix this?

The code below comes from woocommerce/templates/myaccount/my-orders.php

if ($actions) { foreach ( $actions as $key => $action ) { echo '<a
 href="' . esc_url( $action['url'] ) . '" class="button ' .
 sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) .
 '</a>'; }

It generates the "Print" button on the "my orders" page. I am using mqtranslate german/englisch. In the german version everything works- the links are correct, ony when i switch the language there are "%2f" instead of "/". But also only after the first part (until myaccount/) - because some "/" are correctly encoded.

Also in the english version it's a "&" before "print-order-type=receipt" instead of a "?".

like image 670
ad2003 Avatar asked Jun 11 '14 14:06

ad2003


2 Answers

Use decodeURIComponent on the copied value:

decodeURIComponent('myaccount/?lang=en%2Fprint-order%2F2067%2F?print-order-type=receipt')

http://jsfiddle.net/7hySU/

like image 81
Alex W Avatar answered Oct 22 '22 05:10

Alex W


do this:

echo '<a href="' . urldecode($action['url'] ) ....

More about this: http://us1.php.net/manual/en/function.urldecode.php

urldecode() is doing egzactly what you are looking for. Just apply it in your foreach loop.

This will solve your problem

Cheers :)

You can try it at http://3v4l.org/mhVuV kind of phpfiddle :)

put this in the box:

    echo urldecode("myaccount/?lang=en%2Fprint-order%2F2067%2F&print-order-type=receipt");
like image 2
Vladd Avatar answered Oct 22 '22 04:10

Vladd