cviebrock / eloquent-taggable

Easily add the ability to tag your Eloquent models in Laravel.
MIT License
559 stars 72 forks source link

Problem with accents #116

Closed pierrocknroll closed 3 years ago

pierrocknroll commented 3 years ago

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

cviebrock commented 3 years ago

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?

pierrocknroll commented 3 years ago

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.

cviebrock commented 3 years ago

@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.

cviebrock commented 3 years ago

This should be out in the 8.0.2 release shortly.