Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Fix logging empty strings - fix microsoft/vscode#52028
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Jun 24, 2018
1 parent cd025f4 commit 4d3dc83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/chrome/consoleHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function resolveParams(m: Crdp.Runtime.ConsoleAPICalledEvent, skipFormatSpecifie

const processedArgs: Crdp.Runtime.RemoteObject[] = [];
const pushStringArg = (strArg: string) => {
if (strArg) {
if (typeof strArg === 'string') {
processedArgs.push({ type: 'string', value: strArg });
}
};
Expand All @@ -106,6 +106,8 @@ function resolveParams(m: Crdp.Runtime.ConsoleAPICalledEvent, skipFormatSpecifie
const formatSpec = formatSpecifiers.shift();
const formatted = formatArg(formatSpec, arg);

currentCollapsedStringArg = currentCollapsedStringArg || '';

if (typeof formatted === 'string') {
if (formatSpec) {
// If this param had a format specifier, search and replace it with the formatted param.
Expand All @@ -117,12 +119,15 @@ function resolveParams(m: Crdp.Runtime.ConsoleAPICalledEvent, skipFormatSpecifie
// `formatted` is an object - split currentCollapsedStringArg around the current formatSpec and add the object
const curSpecIdx = currentCollapsedStringArg.indexOf('%' + formatSpec);
const processedPart = currentCollapsedStringArg.slice(0, curSpecIdx);
pushStringArg(processedPart);
if (processedPart) {
pushStringArg(processedPart);
}

currentCollapsedStringArg = currentCollapsedStringArg.slice(curSpecIdx + 2);
processedArgs.push(formatted);
} else {
pushStringArg(currentCollapsedStringArg);
currentCollapsedStringArg = '';
currentCollapsedStringArg = null;
processedArgs.push(formatted);
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/chrome/consoleHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ suite('ConsoleHelper', () => {
doAssertForString(Runtime.makeLog('foo %O bar %O etc %O more', 'test', 1, null, undefined, NaN), 'foo test bar 1 etc null more undefined NaN');
});

test('empty strings', () => {
doAssertForString(Runtime.makeLog(''), '');
});

test('string and object', () => {
const result = ConsoleHelper.formatConsoleArguments(Runtime.makeLog('foo', '$obj', 'bar'));
assert.equal(result.isError, false);
Expand Down

0 comments on commit 4d3dc83

Please sign in to comment.