Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript do not escape \ character?

Tags:

javascript

I'm building a query for YQL, and I've ran into a dumb issue. I wont be pasting in the entire query as there is no need, just the part I'm having the issue with:

var query = encodeURI("... and xpath='//div[@class=\\'body bodySign\\']/p' ...")';

As you may notice, I've added two \ characters, it is need for the actual query. I'm using multi queries, and I need to double esacpe the ' character in order for them to parse correctly inside YQL.

But JavaScript escapes the \ character. It doesn't matter how many \ I add (to "escape" to following \ character) I still get left with only one \ in my query.

How do I keep multiple \ characters without them escaping each other?

Thanks

like image 536
Matt Avatar asked Nov 13 '22 06:11

Matt


1 Answers

It should be

var query = encodeURI("... and xpath='//div[@class=\\\\'body bodySign\\\\']/p' ...")';

For example, hit F12 and look at the output of console.log("\\\\").

like image 164
forivall Avatar answered Nov 14 '22 23:11

forivall