-
Notifications
You must be signed in to change notification settings - Fork 298
fix(Price): 组件传入异常信息直接原样返回 #3440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| const CJK = /[\u4E00-\u9FFF]/ | ||
| const RE_NUM = /\d+(?:\.\d+)?/g | ||
|
|
||
| function hasNoExtractablePrice(s: string) { | ||
| const t = s.trim() | ||
| if (!t) return true | ||
| if (!/\d/.test(t)) return true | ||
| if (t.replace(/[^\d.]/g, '') === '') return true | ||
| return false | ||
| } | ||
|
|
||
| export function shouldRenderPriceAsRaw(s: string) { | ||
| if (hasNoExtractablePrice(s)) { | ||
| return true | ||
| } | ||
| const t = s.trim() | ||
| if (!CJK.test(t)) return false | ||
| const matches = Array.from(t.matchAll(RE_NUM)) | ||
| if (matches.length < 2) return false | ||
| const a = matches[0] | ||
| const b = matches[1] | ||
| const i0 = a.index! | ||
| const i1 = b.index! | ||
| const between = t.slice(i0 + a[0].length, i1) | ||
| return CJK.test(between) | ||
| } | ||
|
Comment on lines
+12
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 判定规则较窄,部分常见异常入参不会进入原样渲染分支。 当前规则要求「至少两个数字 + 第一/第二个数字之间存在 CJK」。对于单数字 + CJK 的常见异常文案(如 如果产品意图是「字符串里只要明显不是单一价格就原样渲染」,可考虑改成更宽松的判定,例如:当字符串包含 CJK(或除 此外 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Web 版
price.tsx未同步该修复,跨端行为将不一致。本次只在
price.taro.tsx引入shouldRenderPriceAsRaw与renderRawContent;从提供的src/packages/price/price.tsx:108-155可以看到 web 版仍直接使用formatThousands(price)/formatDecimal(price)的格式化路径,并没有 raw 渲染分支。这意味着同样传入异常字符串(如"10元起到200元")时,小程序/鸿蒙端会原样输出,而 H5 端会被replace(/[^\d.]/g, '')清洗后渲染为错误数字(如10.200),违反 PR 标题「组件传入异常信息直接原样返回」的承诺。建议在
src/packages/price/price.tsx中按相同模式加上isRenderPriceRaw判定与 raw 渲染分支,保持双端一致。Also applies to: 176-193
🤖 Prompt for AI Agents