5
  • Context: HTML web page (jade/node.js/javascript)
  • image url has strings with spaces/non-ascii characters
  • I need to encode these strings either with escape or urlencode.
  • as of now I am using escape to encode spaces specifically.

But I am not able justify/understand whether I should use escape to encode strings or should I use encodeurlcomponent. I tried reading some online blogs but not understood yet.

Any pointers to which one should be used under what circumstances.

GJain
  • 5,025
  • 6
  • 48
  • 82

1 Answers1

7
  • escape() will not encode: @*/+

  • encodeURI() will not encode: ~!@#$&*()=:/,;?+'

  • encodeURIComponent() will not encode: ~!*()'

For more information, have a look at these questions:

Encode URL in JavaScript?

When are you supposed to use escape instead of encodeURI / encodeURIComponent?

Community
  • 1
  • 1
Danny Beckett
  • 20,529
  • 24
  • 107
  • 134