fix: replaceText 替换文本不全 (#3687)

Co-authored-by: xiaolong <xiaolong@xiaolongdeMacBook-Pro.local>
This commit is contained in:
biley 2022-03-03 17:06:24 +08:00 committed by GitHub
parent 58e0f27110
commit 4d21633a71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -518,13 +518,13 @@ export function render(
// 进行文本替换
if (env.replaceText && isObject(env.replaceText)) {
const replaceKeys = Object.keys(env.replaceText);
replaceKeys.sort().reverse(); // 避免用户将短的放前面
replaceKeys.sort((a, b) => b.length - a.length); // 避免用户将短的放前面
const replaceTextIgnoreKeys = new Set(env.replaceTextIgnoreKeys || []);
JSONTraverse(schema, (value: any, key: string, object: any) => {
if (typeof value === 'string' && !replaceTextIgnoreKeys.has(key)) {
for (const replaceKey of replaceKeys) {
if (~value.indexOf(replaceKey)) {
object[key] = value.replaceAll(
value = object[key] = value.replaceAll(
replaceKey,
env.replaceText[replaceKey]
);