cviebrock/eloquent-taggable

Problem with accents

pierrocknroll opened this issue · 4 comments

Hello,
I think there is a potential bug or at least there should be an explanation in the readme.

Depending on how the database collation is, tags with accents can be problematic.
Example with two words in French which do not have the same meaning at all:

$model->tag('Péché');

and

$model->tag('Peche');

they will be linked to the same tag (Péché) if the normalized column in the database is not in "XXX_bin". I had the problem with my column in utf8mb4_unicode_ci

Thanks

Hey @pierrocknroll ... how do you suggest I change this? Adding a ->collation(...) to the normalized column in the migration? I'm just not sure what collation to use ... utf8mb4_bin probably?

Yes !
We should make sure that this does not cause problems on databases that are not utf8, or that it does not generate other bugs, but I don't think so.

@pierrocknroll take a look at my suggested fix above and let me know what you think.

The issue never showed up in testing because SQLite does binary collation be default. When I swapped out SQLite for a local MySQL DB, I confirmed your problem and the above change seems to fix it.

I also tried to make an educated guess as to the proper collation to use, based on the charset of the database, which I think answers your concern about assuming the DB is UTF8.

This should be out in the 8.0.2 release shortly.