diff --git a/src/messages.ts b/src/messages.ts index cf18a666e..60c17e686 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -588,8 +588,16 @@ export class Messages { } const messages = ensureArray(msg); return messages.map((message) => { - ensureString(message); - return util.format(message, ...tokens); + const msgStr = ensureString(message); + // If the message does not contain a specifier, util.format still appends the token to the end. + // The 'markdownLoader' automatically splits bulleted lists into arrays. + // This causes the token to be appended to each line regardless of the presence of a specifier. + // Here we check for the presence of a specifier and only format the message if one is present. + // https://nodejs.org/api/util.html#utilformatformat-args + // https://regex101.com/r/8Hf8Z6/1 + const specifierRegex = new RegExp('%[sdifjoO]{1}', 'gm'); + + return specifierRegex.test(msgStr) ? util.format(msgStr, ...tokens) : msgStr; }); } } diff --git a/test/unit/messagesTest.ts b/test/unit/messagesTest.ts index a72e1a10b..63ab1f11b 100644 --- a/test/unit/messagesTest.ts +++ b/test/unit/messagesTest.ts @@ -67,14 +67,14 @@ describe('Messages', () => { it('should return single string from array of messages', () => { expect(messages.getMessage('manyMsgs', ['blah', 864])).to.equal( - `hello blah 864${EOL}world blah 864${EOL}test message 2 blah and 864` + `hello${EOL}world${EOL}test message 2 blah and 864` ); }); it('should return multiple string from array of messages', () => { expect(messages.getMessages('manyMsgs', ['blah', 864])).to.deep.equal([ - 'hello blah 864', - 'world blah 864', + 'hello', + 'world', 'test message 2 blah and 864', ]); });