Repository navigation
fix: preserve non-Latin scripts in select-option values and detail linting - #53
Merged
Merged
Conversation
slugify() is ASCII-only, so it was reused to derive select-option machine values from labels. All-Thai/Vietnamese/Cyrillic/Greek option lists folded to the same empty/collapsed value, and the linter then flagged and deleted the "duplicates". Diacritics (Café) and tone marks (má vs mà) were also stripped even though they're semantically distinct. - Add canonicalizeOptionValue() (utils.ts): Unicode-safe canonicalizer that keeps letters/marks/numbers from any script, only drops variation selectors and orphan combining marks. Falls back to the raw label when nothing usable remains (emoji-/punctuation-only). - Wire it into the builder (payloadBuilder.ts parseOptions, buildTranslationsPayload), the linter (lint/shared.ts parseCanonicalOptions, lint/strictMetrics.ts), and import (applyFields.ts) so generation, validation, and round-trip agree. - validateAndCapitalizeCommaList (lint/shared.ts) now capitalizes only the label half of an explicit "value:label" option, instead of corrupting the value prefix. - checkManualIdHygiene (lint/shared.ts) warning text now only claims "non-ASCII" when the offending ID actually is; the slug-safety regex also rejects plain-ASCII input (uppercase, spaces, underscores), which was getting the same misleading message. - Add regression tests for Thai, Vietnamese, Cyrillic, Greek, and emoji-only option values.
checkUnreferencedDetails only matched a detail against a category's Fields column via slug (slugify(token)), but slugify() is ASCII-only and returns "" for names like Thai. Every such detail was flagged and reported as unreferenced even when correctly referenced by name, because the linter's matching didn't mirror the builder. The builder (payloadBuilder fieldNameToId) actually resolves a category's field reference by exact name or lowercase name first, falling back to the slug. Match the detail's raw/lowercase name the same way, in addition to slug and explicit ID.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8105aba07
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
parseOptions falls back to the raw label as `value` when canonicalizeOptionValue(label) is empty (emoji-/punctuation-only labels, e.g. "❤️"). Three call sites that reconstruct the same "value:label" string for matching against spreadsheet/translation source text compared `value` against the empty canonical form instead of that same fallback, so bare options like "❤️" were rewritten as "❤️:❤️" and no longer exact-matched the source string — silently dropping option translations and lint metrics. Fixes reported by automated review (Codex, Greptile) on PR #53: - payloadBuilder.ts buildTranslationsPayload - lint/strictMetrics.ts buildLintTranslationsByLocale - importCategory/applyFields.ts (import round-trip) Also regenerates version.ts, which still pointed at the branch this work was originally (mistakenly) committed on before being moved to this branch.
parseExtractedFiles (the live import path from src/importCategory.ts) fell back to createOptionValue() -> slugify() when an imported option lacked an explicit `value`. slugify() is ASCII-only, so a third-party or older .comapeocat with non-Latin option labels and no explicit values would get index-based fallback values (e.g. "field-1") on import instead of the label. Because applyFields.ts now treats any value differing from canonicalizeOptionValue(label) as "explicit" and preserves it verbatim as "value:label", that collapsed fallback value would then survive every future round-trip. Use canonicalizeOptionValue(label) || label, matching parseOptions' own fallback, so import stays consistent with generation. Reported by Greptile CLI review of PR #53.
The old assertTrue OR'd in canonicalizeOptionValue("hearts") === "",
which the preceding assertEqual already established as true — making
the assertion pass unconditionally regardless of its left side. It
never actually exercised cross-emoji collision behavior.
Assert what the comment claims: two different emoji-only options both
canonicalize to "", but the `canonicalizeOptionValue(x) || x` fallback
callers actually use keeps them distinct.
Found by pr-critical-reviewer during final PR readiness pass on #53.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two related bugs found while working on Thai/non-Latin-script support: select-option machine values and the "unreferenced detail" linter both relied on
slugify(), which is ASCII-only.The bugs
parseOptions/parseCanonicalOptionsderived a select option's storedvaluefromslugify(label). For all-Thai / all-Vietnamese / all-Cyrillic / all-Greek option lists, every label slugified to""(or to the same collapsed string), so distinct options collided and the linter flagged/deleted the "duplicates". Diacritics (Café) and tone marks (mávsmà) were also stripped even though they're semantically distinct in those languages.checkUnreferencedDetailsonly matched a detail against a category's Fields column viaslugify(token). The builder (payloadBuilder.tsfieldNameToId) actually resolves references by exact/lowercase name first, falling back to slug — the linter didn't mirror that, so every non-Latin-named detail (e.g. Thai) was falsely reported as unreferenced.The fix
canonicalizeOptionValue()(utils.ts): a Unicode-safe canonicalizer for option values that keeps letters/marks/numbers from any script (only strips variation selectors and orphan combining marks), unlikeslugify()which stays ASCII-only for entity IDs (.comapeocatpackager restricts those to^[a-zA-Z0-9_-]+$). Falls back to the raw label when nothing usable remains (emoji-/punctuation-only options).payloadBuilder.ts), the linter (lint/shared.ts,lint/strictMetrics.ts), and import (applyFields.ts) so generation, validation, and round-trip all agree.validateAndCapitalizeCommaListnow capitalizes only the label half of an explicitvalue:labeloption instead of corrupting the value prefix.checkManualIdHygiene's warning text now only claims "non-ASCII" when the ID actually is — the slug-safety regex also rejects plain-ASCII input (uppercase, spaces, underscores), which was getting the same misleading message.checkUnreferencedDetailsnow matches a detail's raw/lowercase name (in addition to slug and explicit ID), mirroring the builder's actual resolution order.Verification
bunx tsc --noEmit— cleanbunx biome lint .— cleancanonicalizeOptionValue()in Node against every assertion in the new test to confirm behavior (Thai/Vietnamese/Cyrillic/Greek stay distinct, diacritics preserved, emoji-only → falls back to raw label).Note
This branch was rebuilt from a clean
mainbase after an earlier push accidentally landed these commits on PR #51's branch, which explicitly scoped them out. That mistake was corrected before opening this PR.Greptile Summary
This PR preserves non-Latin select-option values and aligns lint/import behavior around the same canonical form. The main changes are:
canonicalizeOptionValue()for Unicode-safe option machine values.value:labeloption prefixes unchanged during label capitalization.src/version.tsmetadata for the current branch.Confidence Score: 5/5
Safe to merge with low risk.
The changed build, import, lint, and translation paths now share the same Unicode option canonicalization and raw-label fallback behavior. Prior emoji fallback drift cases are addressed in the updated reconstruction code. No blocking correctness or security issues were found.
No files require special attention.
What T-Rex did
Important Files Changed
Sequence Diagram
Reviews (4): Last reviewed commit: "test: replace tautological emoji-collisi..." | Re-trigger Greptile