Skip to content

Commit

Permalink
fix:正则表达式兼容safari
Browse files Browse the repository at this point in the history
  • Loading branch information
昔梦 committed Aug 24, 2024
1 parent 6d324e7 commit 0cd9122
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/form-render/src/models/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export const parseExpression = (func: any, formData = {}, parentPath: string | [
if (typeof func === 'string') {
const formatFunc = func.replace(/\[(\w+)\]/g, '.$1'); // 将[]替换为.xxxxx
const funcBody = formatFunc.replace(/^{\s*{/g, '').replace(/}\s*}$/g, '').trim();
const funcBodyStr = funcBody.replace(/(?<!\d)(\.|\?\.)(?!\d)/g, '?.'); // 将. 和 ?. 统一替换为?. 并排除数字中的.
const funcBodyTemp = funcBody.replace(/(\.|\?\.)/g, '?.'); // 将. 和 ?. 统一替换为?.
const funcBodyStr = funcBodyTemp.replace(/(\d+)\?\.(\d+)/, '$1.$2'); // 排除数字中的?.

This comment has been minimized.

Copy link
@Aliveing

Aliveing Sep 10, 2024

这只会改第一数字的?.,请将正则替换成:/(\d+)\?\.(\d+)/g

const funcStr = `
return ${funcBodyStr
.replace(/formData/g, JSON.stringify(formData))
Expand Down

0 comments on commit 0cd9122

Please sign in to comment.