0

I'm only asking because I tried sending an email (with PEAR) which containd an image whose name was something like "header image_3021" and noticed that it didn't show up in the email.

When I checked the SRC in the recieved email the space was replaced with + and that somehow made the link point to the wrong file. Now, IIRC, + is a correct encoding for spaces in URLs yet the browser could not locate "header+image_2031".

I checked the original content of the email both with Gmail's show original and in the server logs and the space was still there, so the replacement was done either by the browser or by Gmail's rendering process.

I have since modified my upload algorithms to not allow spaces in filenames but I have to ask: What's the best way to make sure the browser will display images with spaces in their file names? Replace them with %20 myself? Let the browser do it? Just disallow them?

Bogdan
  • 1,869
  • 6
  • 24
  • 53
  • why manually? you've got functions to encode urls like for php you have `urlencode()` – Mr. Alien Feb 26 '13 at 14:37
  • I said manually because that still requires me to go trough the email body, find the URLS and use urlencode on them. Also as you can see the browser (or gmail?) already did the encoding but did it wrong. that's why I'm asking. I thought browsers can handle spaces by themselves. – Bogdan Feb 26 '13 at 14:40

1 Answers1

0

Definitely encode them. By doing so, you remove the nuance of how different clients will interpret the string. As @mr alien said, there are out of box php functions that will handle that for you.

Brad
  • 6,106
  • 4
  • 31
  • 43
  • If you're URLs are being created on the client side via JS, this shows you how to encode it at the point of entry so you don't have to read over the body of the email: http://stackoverflow.com/questions/332872/how-to-encode-a-url-in-javascript – Brad Feb 26 '13 at 14:44
  • Thanks. I will try to encode the filenames from now on. Tho sanitizing a customer-made email like that is tricky work... – Bogdan Feb 26 '13 at 15:01