mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
fix: 修复 fx 的 replace 方法可能死循环的问题 (#10539)
This commit is contained in:
parent
9b5a7daa4d
commit
47535fcc88
@ -598,3 +598,12 @@ test('evalute:speical characters', () => {
|
||||
expect(evaluate('${1 | 2}', {})).toBe(3);
|
||||
expect(evaluate('${1 | abc}', {abc: 2})).toBe(3);
|
||||
});
|
||||
|
||||
test('evalute:replace', () => {
|
||||
const data = {};
|
||||
expect(evaluate('${REPLACE("abcdefg", "abc", "cbd")}', data)).toBe('cbddefg');
|
||||
expect(evaluate('${REPLACE("abcdefg", "efg", "efg")}', data)).toBe('abcdefg');
|
||||
expect(evaluate('${REPLACE("abcdefg", "abc", "abcabc")}', data)).toBe(
|
||||
'abcabcdefg'
|
||||
);
|
||||
});
|
||||
|
@ -1441,6 +1441,9 @@ export class Evaluator {
|
||||
return result;
|
||||
}
|
||||
|
||||
const shouldLoop = !(
|
||||
typeof replace === 'string' && replace.includes(search)
|
||||
);
|
||||
while (true) {
|
||||
const idx = result.indexOf(search);
|
||||
|
||||
@ -1452,6 +1455,10 @@ export class Evaluator {
|
||||
result.substring(0, idx) +
|
||||
replace +
|
||||
result.substring(idx + search.length);
|
||||
|
||||
if (!shouldLoop) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user