fix(web): support punctuation in markdown form field names (#38651)

This commit is contained in:
KVOJJJin 2026-07-10 15:08:07 +08:00 committed by GitHub
parent 489e77658e
commit 3c8e0e2113
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -534,6 +534,26 @@ describe('MarkdownForm', () => {
// Unicode letters should be valid form field names.
describe('Unicode name support', () => {
it('should include fields whose names contain supported full-width and half-width punctuation', async () => {
const user = userEvent.setup()
const node = createRootNode(
[
createElementNode('input', { type: 'hidden', name: '字段()!*&-', value: 'full-width' }),
createElementNode('input', { type: 'hidden', name: 'field()!*&-', value: 'half-width' }),
createElementNode('button', {}, [createTextNode('Submit')]),
],
{ dataFormat: 'json' },
)
render(<MarkdownForm node={node} />)
await user.click(screen.getByRole('button', { name: 'Submit' }))
await waitFor(() => {
expect(mockOnSend).toHaveBeenCalledWith('{"字段()!*&-":"full-width","field()!*&-":"half-width"}')
})
})
it('should include Unicode-named fields from all supported controls in JSON output', async () => {
const user = userEvent.setup()
const node = createRootNode(

View File

@ -43,7 +43,7 @@ const SUPPORTED_TYPES_SET = new Set<string>(Object.values(SUPPORTED_TYPES))
const SAFE_NAME_RE = (() => {
try {
return new RegExp('^\\p{L}[\\p{L}\\p{M}\\p{N}_-]*$', 'u')
return new RegExp('^\\p{L}[\\p{L}\\p{M}\\p{N}_()!*&-]*$', 'u')
}
catch {
// Fallback for browsers without Unicode property escape support.