Skip to content

Don't error for bad locale strings - #1117

Merged
zetter-rpf merged 1 commit into
mainfrom
dont-error-on-bad-locales
Nov 17, 2026
Merged

zetter-rpf merged 1 commit into
mainfrom
dont-error-on-bad-locales

Conversation

@zetter-rpf

@zetter-rpf zetter-rpf commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes https://raspberrypifoundation.sentry.io/issues/7848588785/events/latest/?environment=production&project=6143981&query=is%3Aunresolved&referrer=latest-event

Previously a mailformed request such as
/api/projects/blank-python-starter?locale=en-US%00%2f%2e%2e%2f... reached Postgres with a null byte in the bind parameter, so PG raised a "string contains null byte" error.

This change makes ProjectLoader ignore any requested locale that is not between two and eight letters or hyphens, before falling back to 'en'.

I've decided on quite a loose regex for locales as the locales we support for projects are different to the ones supported in this app in locales.rb and I didn't want to possibly valid future locales.

@cla-bot cla-bot Bot added the cla-signed label Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Test coverage

94.19% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/44068622459

@raspberrypiherokubot
raspberrypiherokubot temporarily deployed to editor-api-p-dont-error-ixyfbt November 17, 2026 10:50 Inactive
https://raspberrypifoundation.sentry.io/issues/7848588785/events/latest/?environment=production&project=6143981&query=is%3Aunresolved&referrer=latest-event

Previously a mailformed request such as
`/api/projects/blank-python-starter?locale=en-US%00%2f%2e%2e%2f...` reached Postgres with a null byte in the bind parameter, so PG raised a "string contains null byte" error.

This change makes ProjectLoader ignore any requested locale that is not between two and eight letters or hyphens, before falling back to `'en'`.

I've decided on quite a loose regex for locales as the locales we support for projects are different to the ones supported in this app in locales.rb and I didn't want to possibly valid future locales.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zetter-rpf
zetter-rpf force-pushed the dont-error-on-bad-locales branch from f0dfd52 to b609ed5 Compare November 17, 2026 10:51
@zetter-rpf
zetter-rpf temporarily deployed to editor-api-p-dont-error-ixyfbt November 17, 2026 10:51 Inactive
@zetter-rpf zetter-rpf changed the title Return a project instead of a 500 for junk locales Don't error for bad locale string Nov 17, 2026
@zetter-rpf zetter-rpf changed the title Don't error for bad locale string Don't error for bad locale strings Nov 17, 2026
@zetter-rpf
zetter-rpf marked this pull request as ready for review November 17, 2026 10:51
@macroscopeapp

macroscopeapp Bot commented Nov 17, 2026

Copy link
Copy Markdown

Approvability

Verdict: Would Approve

Macroscope's review found this PR approvable — Malformed locale preferences are now ignored while preserving existing project-selection fallbacks. The change is limited to lookup input filtering, with regression coverage for malformed input and preference ordering.

Needs human approval because:

  • approvability is in preview mode for this repository — Macroscope would have approved this PR outside preview mode

You can add or adjust custom eligibility rules. Learn more.

@zetter-rpf
zetter-rpf merged commit 0339578 into main Nov 17, 2026
10 checks passed
@zetter-rpf
zetter-rpf deleted the dont-error-on-bad-locales branch November 17, 2026 11:55

This branch was previously deployed

1 inactive deployment
editor-api-p-dont-error-ixyfbt — b609ed5e Deployed Nov 17, 2026 by zetter-rpf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants