Js2Py icon indicating copy to clipboard operation
Js2Py copied to clipboard

decodeURIComponent ERROR report

Open pendave opened this issue 9 years ago • 4 comments

js2py.base.PyJsException: ReferenceError: decodeURIComponent is not defined

Is this js command not supported? Thanks

pendave avatar Sep 29 '16 08:09 pendave

No, not implemented yet. You can always define them though:

import js2py
context = js2py.EvalJs()
context.execute("""escape = function(text){pyimport urllib; return urllib.quote(text)};
unescape = function(text){pyimport urllib; return urllib.unquote(text)};
encodeURI = function(text){pyimport urllib; return urllib.quote(text, safe='~@#$&()*!+=:;,.?/\\'')};
decodeURI = unescape;
encodeURIComponent = function(text){pyimport urllib; return urllib.quote(text, safe='~()*!.\\'')};
decodeURIComponent = unescape;""")

That's just a basic example that can handle most common instances, you might need to extend on it if you need unicode support or hit a corner case.

worstperson avatar Sep 29 '16 22:09 worstperson

Cool

pendave avatar Sep 30 '16 11:09 pendave

That's an omission, will fix that problem soon!

PiotrDabkowski avatar Nov 05 '16 03:11 PiotrDabkowski

This is still broken =P

miigotu avatar Apr 18 '20 19:04 miigotu