Public: anyone can read this; the crew can change it.

Every username field's pattern is one a browser can read #13800

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

Every username field now takes its pattern from one shared constant with the dash escaped, so browsers can compile it. A new test fails if a literal page pattern stops compiling. It's pushed.

Notes

shipped production is serving it deploy 59903fa

opened this

Every username field now takes its pattern from one shared constant with the dash escaped, so browsers can compile it. A new test fails if a literal page pattern stops compiling. It's pushed.

What changed

  • New src/web/username_pattern.ts exports USERNAME_PATTERN as [A-Za-z0-9][A-Za-z0-9._\-]*. The dash is escaped because browsers compile pattern with the v flag, where a bare - in a character class is a syntax error.
  • Eight pages now use the constant: everyday, crew, apps, org, site (both fields), migrate, claim and start_claim. The issue named seven places; I also changed claim.ts and start_claim.ts, which #13786 is fixing. I did it so the new test passes on this branch alone. If #13786 merges first, those two files will conflict, and either version resolves it.
  • The server-side USERNAME regexes are unchanged, so behaviour is the same.

Test

  • test/username-pattern.test.ts compiles USERNAME_PATTERN with the v flag and checks it accepts and rejects the right names.
  • It also scans src/web/** for literal pattern="…" and pattern: "…" values and compiles each one with the v flag.
  • The scan skips values built with ${…} interpolation, because they have no literal pattern to compile. Its scope is src/web, not all of src; I narrowed it after a description string elsewhere tripped it.
  • I ran the new test against the unfixed source with a stash, which showed two fails, so it fails without the change.

What I ran

  • bun x tsc --noEmit and scripts/gate.ts --fix were clean.
  • The new test and 25 related test files passed (139 pass, 5 skipped, 0 fail). scripts/fast.ts said the diff was too broad to name tests, so I picked those files by name.
  • I did not run the full suite; the forge's check does that on the push.

Push hook

  • The repo's pre-push hook requires a Try: line in a commit message, so the commit has one.

To try it Open /claim in Chrome and type a username with a dash. The console should log no pattern error.

🤖 Generated with Claude Code

Closes #13798

commented

Every username field now takes its pattern from one shared constant with the dash escaped, so browsers can compile it. A new test fails if a literal page pattern stops compiling. It's pushed.

What changed

  • New src/web/username_pattern.ts exports USERNAME_PATTERN as [A-Za-z0-9][A-Za-z0-9._\-]*. The dash is escaped because browsers compile pattern with the v flag, where a bare - in a character class is a syntax error.
  • Eight pages now use the constant: everyday, crew, apps, org, site (both fields), migrate, claim and start_claim. The issue named seven places; I also changed claim.ts and start_claim.ts, which #13786 is fixing. I did it so the new test passes on this branch alone. If #13786 merges first, those two files will conflict, and either version resolves it.
  • The server-side USERNAME regexes are unchanged, so behaviour is the same.

Test

  • test/username-pattern.test.ts compiles USERNAME_PATTERN with the v flag and checks it accepts and rejects the right names.
  • It also scans src/web/** for literal pattern="…" and pattern: "…" values and compiles each one with the v flag.
  • The scan skips values built with ${…} interpolation, because they have no literal pattern to compile. Its scope is src/web, not all of src; I narrowed it after a description string elsewhere tripped it.
  • I ran the new test against the unfixed source with a stash, which showed two fails, so it fails without the change.

What I ran

  • bun x tsc --noEmit and scripts/gate.ts --fix were clean.
  • The new test and 25 related test files passed (139 pass, 5 skipped, 0 fail). scripts/fast.ts said the diff was too broad to name tests, so I picked those files by name.
  • I did not run the full suite; the forge's check does that on the push.

Push hook

  • The repo's pre-push hook requires a Try: line in a commit message, so the commit has one.

To try it Open /claim in Chrome and type a username with a dash. The console should log no pattern error.

🤖 Generated with Claude Code

commented

I merged main into the branch and pushed it. The merge conflicted in src/web/pages/claim.ts and src/web/pages/start_claim.ts, and I resolved both.

Conflict: main had changed those two username fields back to an inline "[A-Za-z0-9][A-Za-z0-9._\\-]*" pattern. Both files now use the shared USERNAME_PATTERN from src/web/username_pattern.ts again. No other copy of that inline pattern is left under src/web/pages.

Checks:

  • bun x tsc --noEmit ran clean.
  • bun test on test/username-pattern.test.ts, test/claim-link.test.ts and test/claim-page-words.test.ts passes: 24 tests, 0 failures.
  • I did not run the full suite. scripts/fast.ts named 2096 of 3560 files, an estimated 177 minutes, so I ran the tests nearest the change by hand and left the full check to the forge.
  • bun scripts/gate.ts --fix complained that the pull adds src/web/username_pattern.ts with no terminal screen or how-to doc, and that it changes pages with no look. I added "No door:" and "No look:" lines to the merge commit message to answer both.

To look at: I haven't seen the forge's check verdict on the new push, so that is the confirmation to wait for.

Approved

Approved. The preview serves pattern="[A-Za-z0-9][A-Za-z0-9._\-]*" on /signup, which compiles under the v flag. All username fields share one constant, the server regexes are unchanged, and the test fails without the fix. Nothing here changes layout, keyboard or JS-off behaviour.

Two things to do next:

  1. Drop the unrelated comment rewraps in crew.ts (three hunks) from this pull. They are gate noise and make the diff harder to read.
  2. Move the test's scan to cover multi-line and single-quoted pattern literals, so a future pattern written another way is not skipped without anyone noticing.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs