5

The URLEncodedFormat() function does something that I specifically want which is this:

Generates a URL-encoded string. For example, it replaces spaces with %20

Why does EncodeForURL() not do this? It replaces spaces with a plus "+" symbol instead which is stopping my URLs working.

How would I be able to get around this other than using URLEncodedFormat()?

volume one
  • 6,800
  • 13
  • 67
  • 146
  • 3
    see http://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20 Why don't you want to use URLEncodedFormat()? – ryber Aug 26 '14 at 22:36
  • I have no choice but to go back to URLEncodedFormat() I guess. The reason I wanted to avoid it was because it is meant to be deprecated and superseded by EncodeForURL(). However I run into another problem: if a user wants to edit a URL, then I must display the URL in an form input element. But URLDecode() doesn't remove the %20 for spaces when decoding. – volume one Aug 26 '14 at 22:50
  • 3
    *URLDecode() doesn't remove the %20 for spaces when decoding* Sure it does. Though the new encode function has a matching decode function : [DecodeFromURL](https://wikidocs.adobe.com/wiki/display/coldfusionen/DecodeFromURL) – Leigh Aug 27 '14 at 00:22
  • Are you sure? I'm almost certain that when I tried to display an encoded URL in a form text field using URLDecode() that the %20 remained. I had to write a Replace() to get rid of it. However I didn't know about DecodeFromURL() which seems to work nicely. I was using Canonicalize() on the encoded URL to get back a readable value. – volume one Aug 27 '14 at 00:32
  • @volumeone - I have to take off, but .. yes, I had already tested it and works fine for me. Maybe we are doing something different? Can you edit your question to include a small (stand-alone) repro case? – Leigh Aug 27 '14 at 00:34
  • You want to display the entire url in a single form field? That's hardly user friendly. – Dan Bracuk Aug 27 '14 at 00:49
  • 1
    Adobe added to their `EncodeForURL` doc: `EncodeForURL encodes spaces as '+'. If '%20' is desired, then replace '+' with '%20' after encoding the string.` https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-e-g/encodeforurl.html – Bernhard Döbler Jul 17 '18 at 08:12

0 Answers0