4

I'm facing a weird problem with the Safari browser for Windows.

I have an HTML5 drag-n-drop upload form based on jQuery. It works fine with all the browsers except Safari where, for files with specific extensions, the file name is padded with non-ascii characters after the file extension.

E.g., file example.mov becomes example.movçðÆê

Also the files are corrupted: they seem to have no content.

Is this a known issue with Safari and jQuery/HTML5? Is there any way to filter-out non-ascii characters?

feetwet
  • 3,248
  • 7
  • 46
  • 84
Vasilis
  • 2,721
  • 7
  • 33
  • 54
  • Seeing some code and how you deal with the file on server side would be helpful – Pekka Oct 12 '11 at 22:20
  • On the server side I have a PHP script that receives the post value and stores it in a database, but the problem is that users have already seen the padded name. – Vasilis Oct 12 '11 at 22:26
  • Is this Safari on MAC or PC? Could be the file system itself causing the issue. Have you tried it on a different platform with Safari to see if it still causes the problem? – dSquared Oct 12 '11 at 22:38

1 Answers1

2

I'm not sure if this is useful as, like Pekka, I'm not 100% on the situation here, but if it's enough to strip 'wrong' characters from a string then you could use a regex. This one will remove any characters that aren't a-z, A-Z, 0-9 or ..

filename.replace(/[^a-z0-9\.]+/gi, "");

That may be too restrictive (e.g. you want to allow non-English-like filenames or you only want to strip characters after the extension). Assuming the problem is with the mov and pdf extensions and you only want to remove characters as above from the end of the extension, you could use

filename.replace(/(\.mov|\.pdf)[^a-z0-9\.]+$/i, "$1");
meloncholy
  • 2,122
  • 18
  • 16