fix(Form): reset lastIndex before testing pattern rule - #6982
Merged
Merged
Conversation
kwy404
requested review from
Cat1007,
PengYYYYY,
Wesley-0808,
chaishi,
liweijie0812,
uyarn,
zhangpaopao0609 and
zydemail
as code owners
September 26, 2026 12:23
Collaborator
TDesign Component Site Preview Open
|
commit: |
uyarn
approved these changes
Sep 29, 2026
Collaborator
|
Thanks |
6 of 16 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

这个 PR 的性质是?
相关 Issue
No existing issue.
需求背景和解决方案
Root cause: the
patternvalidator callstest()on the RegExp object from the rule. A regexp with thegoryflag is stateful:test()starts atlastIndexand moves it past the match. The same rule object is reused for every validation, so a valid value passes once and fails the next time. Example: withrules: { name: [{ pattern: /^\d+$/g }] }andname = '123', callingform.validate()three times returnstrue, an error, thentrue.Fix: set
reg.lastIndex = 0beforetest(), so every validation starts at the beginning of the value (async-validator does the same for its pattern rule). Regexps withoutgoryignorelastIndex, so they behave exactly as before.Test: added
pattern with global flaginform.utils.test.tsx, which validates'123'twice against/^\d+$/g. Before the fix the second call returnsfalse(1 failed, 20 passed). After the fix all 21 tests pass, and the whole Form suite passes (91 passed, 3 todo). Prettier, ESLint andtsc --noEmitpass.📝 更新日志
tdesign-vue-next
pattern规则使用带g或y标志的正则时,连续校验隔次失败的问题@tdesign-vue-next/chat
@tdesign-vue-next/nuxt
@tdesign-vue-next/auto-import-resolver
请求合并前的自查清单