discourse/spec/db/post_migrate
Natalie Tay c5b25e313e
FIX: Clean localized tag names (#38488)
Localized tag names were never run through `DiscourseTagging.clean_tag`,
unlike regular tag names. A localized name like `mijn-naam" (123)` would
be stored and rendered as-is, breaking body classes (`tag-mijn-naam"
(123)`) and tag display under topic titles.

This PR adds a `before_validation` callback on `TagLocalization` that
cleans names with `DiscourseTagging.clean_tag`. This covers all three
entry points `TagLocalizationCreator`, `TagLocalizationUpdater`, and
`TagSettingsUpdater` at the model.

Includes a post-migration that cleans existing dirty localization names.
The migration only fetches rows that actually violate, names with
special characters from `TAGS_FILTER_REGEXP`, uppercase when
`force_lowercase_tags` is on, or names exceeding `max_tag_length`. The
actual cleaning still uses `DiscourseTagging.clean_tag` so it respects
site settings. We try to minimize calling application code in
migrations, but this is quite controlled.

Related:
https://meta.discourse.org/t/localized-tags-are-not-slugified/398105
2026-03-12 12:54:50 +08:00
..
20260311064518_clean_existing_tag_localization_names_spec.rb FIX: Clean localized tag names (#38488) 2026-03-12 12:54:50 +08:00