Daniel-Khodabakhsh / datetime-format

Gnome extension which allows users to customise the datetime format on the status bar and date menu.
GNU General Public License v3.0
30 stars 15 forks source link

Unicode support in format strings #5

Open sirrahd opened 6 years ago

sirrahd commented 6 years ago

This change fixes an issue where the Datetime Format GUI fails to load with the error 'Failed to convert locale string to UTF8: Invalid byte sequence in conversion input' if unicode characters are entered in any of the format strings.

Date().toLocaleFormat(format) only accepts ascii characters in the format string. This change works around that limitation by escaping non-ascii characters in the format string before passing the string to toLocaleFormat(), then escaping the result in case non-ascii characters are in the localized string, and finally unescaping the resulting string by passing it to JSON.parse.

sirrahd commented 6 years ago

Thanks Daniel. I did some edge case testing just now on this and found this doesn't handle " and \ characters well, need to escape them to make JSON.parse happy. I will push an update today with these fixes and your requested changes.

sirrahd commented 6 years ago

Just pushed an update that addresses your feedback and fixes the " and \ issues.