swarm-ui: escape the hyphen in create-agent's name pattern
Closes #3423. Modern browsers validate an <input pattern> attribute's regex in Unicode-set ('v') mode, which is stricter about hyphen placement than classic mode: `[a-z0-9-]` throws "Invalid character class" under 'v' mode even though a trailing hyphen is unambiguous (and valid) in classic regex. Reproduced directly: `new RegExp('[a-z0-9-]', 'v')` throws, `new RegExp('[a-z0-9\\-]', 'v')` doesn't. Escaping the hyphen fixes it without changing what the pattern matches.
This commit is contained in:
parent
62d1c6224b
commit
e71e4ef432
1 changed files with 10 additions and 1 deletions
|
|
@ -42,7 +42,16 @@ type SubmitState =
|
||||||
// a `pattern` hint only, not a substitute for the server's own
|
// a `pattern` hint only, not a substitute for the server's own
|
||||||
// validation; a name this rejects would fail server-side anyway, so
|
// validation; a name this rejects would fail server-side anyway, so
|
||||||
// catching it before a round-trip is a pure UX win, not a new gate.
|
// catching it before a round-trip is a pure UX win, not a new gate.
|
||||||
const NAME_PATTERN = '[a-z0-9-]{1,63}';
|
//
|
||||||
|
// Hyphen escaped (`\-`) rather than left trailing in the class: modern
|
||||||
|
// browsers validate the `pattern` attribute's regex in Unicode-set (`v`)
|
||||||
|
// mode, which is far stricter about hyphen placement than classic mode —
|
||||||
|
// `[a-z0-9-]` throws "Invalid character class" under `v` mode even though
|
||||||
|
// it's valid classic-mode regex (a trailing `-` is unambiguous there).
|
||||||
|
// Reproduced directly: `new RegExp('[a-z0-9-]', 'v')` throws,
|
||||||
|
// `new RegExp('[a-z0-9\\-]', 'v')` doesn't — confirmed via mara's console
|
||||||
|
// exception report on this page.
|
||||||
|
const NAME_PATTERN = '[a-z0-9\\-]{1,63}';
|
||||||
|
|
||||||
export function CreateAgentPage() {
|
export function CreateAgentPage() {
|
||||||
const [name, setName] = useState('');
|
const [name, setName] = useState('');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue