Search code examples
javaspringgrailsunicode

Mac Chrome and Mac Safari produces different unicodes


I'm working on a legacy project where we use Java 6 with Spring, Grails, etc.

The problem I'm running into, is that I have an file upload form, where we support support German filenames. In this case I have a file named something with "für" and I'm having difficulties with that now.

I have tried converting it to unicode to see if that solved the problem but I am now able to see why there's a problem. On Mac Chrome, it produces U+308 while on Mac Safari it produces U+00FC, with Safari it works and inserts correctly in MySQL, the other one fails.

The error from MySQL:

#1366 - Incorrect string value: '\xCC\x88r' for column `name` at row 1

When I try running this code:

UPDATE `X` SET `name` = 'für' WHERE `skabelon`.`id` = 1302

Why is there a difference and how can I fix it so it'll work with Chrome on Mac? Windows and Ubuntu Chrome works flawless.

UPDATE
It's now working after Normalizing the string.


Solution

  • It worked after I put it through normalizing in Java. Never knew that I needed that before now.

    I used the Normalizer from java.text

    Normalizer.normalize("String",  Normalizer.Form.NFC)