Repository navigation
docs(router): note that constraint regexes use single backslashes in CFML - #4529
Conversation
…CFML
A route `constraints` value is a plain CFML string that the router drops
into the route regex verbatim (`$patternToRegex` wraps each in a group).
CFML strings have no backslash escapes, so a digit class is written
`"\d{4}"`, not `"\\d{4}"` — a doubled backslash reaches the regex as a
literal backslash and the pattern never matches, so the route silently
falls through. Add a short caution to the "Constrain pattern
placeholders" section (the example there already uses the correct form).
Verified against the router source and the framework's own passing
route specs, which declare `constraints = {year = "\d{4}", ...}` and
compile to a `\d{4}` route regex that matches a numeric path.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Peter Amiri <peter@alurium.com>
|
rev1-r3 review @ 4660584: APPROVE The new caution is accurate. Against source:
Behaviour, probed directly: the constraint is passed as the replacement argument of
I didn't get a standalone Adobe probe running. The single-backslash form is covered on Adobe by the core suite, which the matrix runs on Adobe 2023 and 2025: Wording nit, not blocking: "drops it into the route's regex verbatim" is true of the backslashes, which is the point of the caution. Strictly, the constraint is wrapped in a group and its capturing groups are made non-capturing. Fine to leave as is. PR CI: 20 pass, 4 skipping, 0 fail (including Deploy guides, so the MDX and the |
What
Adds a short caution to the Constrain pattern placeholders section of the v4-2-0 routing guide: a route
constraintsvalue is a plain CFML string, and CFML strings have no backslash escapes, so a digit class is written"\d{4}", not"\\d{4}".A doubled backslash reaches the regex engine as a literal backslash (
\\d= "a backslash, thend"), so"\\d{4}"never matches and the route silently falls through to the next one. The same applies to\w,\s,\.and any other escape.Why it's correct
The router inserts a constraint value into the route's regex verbatim —
Mapper.$patternToRegex()replaces each placeholder with(<constraint>)(inner capturing groups rewritten to non-capturing), so the constraint string is the regex. The framework's own route specs confirm the single-backslash form works: they declareconstraints = {year = "\d{4}", month = "\d{1,2}"}and compile to a^archive\/(\d{4})\/(\d{2})\/?$regex that matchesarchive/2024/05.The example in that section already uses the correct form (
year="\d{4}"); this just makes the rule explicit so readers don't reach for"\\d"out of habit from escape-processing languages.Scope
docs/consumer-ai/.ai/routing.md) does not document constraints, so it's left unchanged; its template copy stays identical (ship-consumer-docs.sh checkpasses).Checks
pnpm --filter @wheels-dev/site-guides build— green (854 pages).pnpm verify:docson the page — 8 passed, 0 failed.tools/build/scripts/ship-consumer-docs.sh check— OK.🤖 Generated with Claude Code