1

First of all, this is my first time using super user. I'm pretty sure that SO isn't the right place to ask this, and this isn't limited to just Mac, as it's with email, so I decided to ask here. If this needs to be migrated, please let me know.

When emailing a file, I noticed that every slash got replaced. I'm on gmail, and when attaching a file named 1/2.pdf, Gmail shows me 1:2.pdfenter image description here

After emailing myself to test, and downloading the pdf for myself, it got downloaded as enter image description here Does anyone know why this is happening?

1 Answer 1

3

Those are two slightly different issues, but neither of them is actually email-related.


When emailing a file, I noticed that every slash got replaced. I'm on gmail, and when attaching a file named 1/2.pdf, Gmail shows me 1:2.pdfenter image description here

That's a macOS (OS X) quirk.

Normally, the slash / is the path separator in OS X (and other operating systems) and therefore not possible to use in file names. If you literally tried to create a file named 1/2.pdf, that would actually be interpreted as "file 2.pdf inside folder 1." This also applies to Linux, Windows, Android, and just about everything else.

But original MacOS (before OS X) used : as the path separator, instead of slash – which was allowed in names then. This still affects old HFS+ formatted disks (which might have filenames with slashes in them) as well as programs built using older toolkits.

So Finder still lets you use / in names, but under the hood it is translated to : when crossing over to the Unix-based core of macOS. (And translated again to / if it goes to a HFS+ disk…)

For example, using the ls command in Terminal you would see that your file is actually /Users/Ryan/1:2.pdf (as opposed to /Users/Ryan/1/2.pdf). And various apps might see the same file as either 1:2.pdf or 1/2.pdf depending on how they were written.

Related posts:


After emailing myself to test, and downloading the pdf for myself, it got downloaded as enter image description here

That's done deliberately by browsers on Windows, because neither / nor : are allowed in file names on Windows – they both work as separators for different things.

In Windows, slash / is used as an alternate path separator alongside the usual backslash \ – for example, the path C:\Users\Ryan can be written as C:/Users/Ryan or C:\Users/Ryan.

Meanwhile the colon : is used both as the drive-letter indicator, and as the alternate stream separator (the latter is like "xattrs" and "resource forks" on macOS).

If a program actually tried to create a file named 1:2.pdf, Windows would interpret it as "file 2.pdf on disk 1:" (yes, Windows drive "letters" can also be numbers); whereas if the program used Downloads/1:2.pdf, that would be interpreted as "directory Downloads, file name 1, alternate stream 2.pdf".

So browsers on Windows have to replace both such characters (and a few more, like ? or * or >) whenever downloading files.

Related:

2
  • "That's done deliberately by browsers on Windows", but I'm on a mac? Great start so far though
    – Ryan Fu
    Commented Jan 14, 2022 at 2:22
  • @Ryan: Ah, the 2nd image looked extremely like the Windows layout – Adobe Reader icon, font, and all. Still – if you're using e.g. Chrome or Firefox, they're very likely to just share the same "lowest common denominator" filtering code across all platforms they run on; for example, I also get such characters replaced with _ even though I'm on Linux where they'd be allowed. (Safari is another topic but even it used to run on Windows for a time...) Commented Jan 14, 2022 at 5:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .