Skip to content

fix(core): preserve locale casing in API locale filter (#1551)#1572

Open
marcusbellamyshaw-cell wants to merge 1 commit into
emdash-cms:mainfrom
Emdash-Bug-Testing:fix/1551-localecode-preserve-casing
Open

fix(core): preserve locale casing in API locale filter (#1551)#1572
marcusbellamyshaw-cell wants to merge 1 commit into
emdash-cms:mainfrom
Emdash-Bug-Testing:fix/1551-localecode-preserve-casing

Conversation

@marcusbellamyshaw-cell

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes the content and search APIs returning zero results when filtering by a locale with an uppercase region or script subtag (e.g. ?locale=zh-TW, pt-BR, zh-Hant).

The localeCode validator applied .transform(v => v.toLowerCase()), but config locales/defaultLocale, the stored locale column, and the public query path all preserve the original BCP-47 casing. SQLite/D1 string comparison is case-sensitive, so the lowercased filter matched nothing. The sibling localeFilterQuery (taxonomies/menus) never lowercased, so this was also an internal inconsistency.

Fix: drop the transform so the value is preserved verbatim. Validation stays case-insensitive (the /i regex is unchanged).

Closes #1551.

Type of change

  • Bug fix

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset (if this PR changes a published package)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 4.8 ultracode

Screenshots / test output

New localeCode validator (#1551) describe in packages/core/tests/unit/api/schemas.test.ts: preserves zh-TW/pt-BR/zh-Hant, still validates case-insensitively, rejects malformed codes, and verifies contentListQuery/contentCreateBody keep the casing.

The `localeCode` validator lowercased the `?locale=` filter and create-body
locale, but config `locales`/`defaultLocale`, the stored `locale` column, and
the public query path all keep the raw BCP-47 casing. As a result the content
and search APIs returned zero rows for any locale with an uppercase region or
script subtag (e.g. zh-TW, pt-BR, zh-Hant).

Drop the `.toLowerCase()` transform so the value is preserved verbatim;
validation stays case-insensitive. This also matches the sibling
`localeFilterQuery` (taxonomies/menus), which never lowercased.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jun 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 03525a6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

localeCode schema lowercases the ?locale= filter, returning zero rows for locales with uppercase subtags

1 participant