Search code examples
javascriptpythonnaked-objects

Getting text missed when & symbol is in a parameter of a js function called by python


I have been using the Naked.toolshed.shell library of python to launch a js script with a gived argument. The problemm is that when "&" is in the argument js only obtains what goes before that symbol, for example Python:

from Naked.toolshed.shell import execute_js, muterun_js
link ="example_of_a_link.com/width=640&crop....."
response = execute_js('/file.js', link)

Js:

var pi = process.argv[2];
console.log(pi);    

And what CMD shows:

example_of_a_link.com/width=640

So & and what goes after is missed, how can I fix it?


Solution

  • You can escape the & with ^ by passing...

    link.replace('&', '^&')
    

    ...to execute_js()