Skip to content

Commit eb151f9

Browse files
committed
fix(log|lib): escape quotemarks in Tree (and JSON copied)
Tencent#678
1 parent 8863bf0 commit eb151f9

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/lib/tool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ const _safeJSONStringifyFlatValue = (value: any, maxLen = 0) => {
206206
if (maxLen > 0) {
207207
value = getStringWithinLength(value, maxLen);
208208
}
209-
str += '"' + getVisibleText(value) + '"';
209+
str += JSON.stringify(value);
210210
} else if (isSymbol(value)) {
211211
str += String(value).replace(/^Symbol\((.*)\)$/i, 'Symbol("$1")');
212212
} else if (isFunction(value)) {
@@ -265,7 +265,7 @@ const _safeJSONStringify = (obj, opt: ISafeJSONStringifyOption, _curDepth = 0) =
265265
if (isObject(key) || isArray(key) || isSymbol(key)) {
266266
opt.ret += Object.prototype.toString.call(key);
267267
} else if (isString(key) && opt.standardJSON) {
268-
opt.ret += '"' + key + '"';
268+
opt.ret += JSON.stringify(key);
269269
} else {
270270
opt.ret += key;
271271
}

src/log/logTool.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ export const getValueTextAndType = (val: any, wrapString = true) => {
3030
text = getPreviewText(val);
3131
} else if (tool.isString(val)) {
3232
valueType = 'string';
33-
text = tool.getVisibleText(val);
3433
if (wrapString) {
35-
text = '"' + text + '"';
34+
text = JSON.stringify(val);
35+
} else {
36+
text = tool.getVisibleText(val);
3637
}
3738
} else if (tool.isNumber(val)) {
3839
valueType = 'number';

0 commit comments

Comments
 (0)