urllib.quote_plus() equivalent in JavaScript
Asked Answered
Z

1

7

Trying to port a snippet of code from Python:

my_input = "this&is£some text"
encoded_input = urllib.quote_plus(str(my_input))

...to JavaScript:

var my_input = "this&is£some text";
encoded_input = encodeURIComponent(my_input);

The minor difference is that urllib.quote_plus() will convert spaces to + instead of %20 (link). Just wondering if anyone could provide any ideas. Currently going with this...

var my_input = "this&is£some text";
encoded_input = encodeURIComponent(my_input).replace(/%20/g,'+');
Zamindar answered 16/5, 2013 at 11:8 Comment(0)
R
4

Use urllib.quote() instead of quote_plus() in your Python code. If changing the Python code is not a solution, your choice of replacing %20 with + is the preferred method anyway (reference, second paragraph in Description).

Ruel answered 16/5, 2013 at 11:11 Comment(1)
Okay, I'll stick to what I'm doing. Accepting this because of reference link provided.Zamindar

© 2022 - 2024 — McMap. All rights reserved.