Saturday, 23 July 2022

Sanitise unicode pair for filename in javascript?

My web-extension fails to initiate file download for filenames having a pair of emojis with invalid filename error, this seems to be some unicode surrogate pair. Here is the offending filename example:

<a href="https://www.example.com/filestream.xyz"
   download="The New World Order Presentation πŸ‘¨‍πŸŒΎπŸ‡³πŸ‡±.pdf"
   target="_blank">Download File</a>

As evident from the 'Chrome devtools DOM elements' screenshot below the farmer emoji (https://emojipedia.org/man-farmer/) seem's to be a combination of multiple code-points and is the reason causing the filename to be invalid. How to sanitise the filenames for such situations in javascript?

The Farmer Emoji



from Sanitise unicode pair for filename in javascript?

No comments:

Post a Comment