From db5ef501a8aaa019879a41313b671b54fc477fae Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Fri, 17 Feb 2017 13:03:25 +0100 Subject: [PATCH] Do not add "undefined" to the beginning of the result of .fixMarkup() Fixes #1452 - Added default return value (empty string) to the ".replace()" call. --- src/highlight.js | 1 + test/api/fixmarkup.js | 21 +++++++++++++++++++++ test/api/index.js | 1 + 3 files changed, 23 insertions(+) create mode 100644 test/api/fixmarkup.js diff --git a/src/highlight.js b/src/highlight.js index 4c9c0658de..189acd4c62 100644 --- a/src/highlight.js +++ b/src/highlight.js @@ -593,6 +593,7 @@ https://highlightjs.org/ } else if (options.tabReplace) { return p1.replace(/\t/g, options.tabReplace); } + return ''; }); } diff --git a/test/api/fixmarkup.js b/test/api/fixmarkup.js new file mode 100644 index 0000000000..61eaaeebc4 --- /dev/null +++ b/test/api/fixmarkup.js @@ -0,0 +1,21 @@ +'use strict'; + +let should = require('should'); +let hljs = require('../../build'); + +describe('.fixmarkup()', function() { + after(function() { + hljs.configure({ useBR: false }) + }) + + it('should not add "undefined" to the beginning of the result (#1452)', function() { + hljs.configure({ useBR: true }) + const value = '{ "some": \n "json" }'; + const result = hljs.fixMarkup(value); + + + result.should.equal( + '{ "some":
"json" }' + ); + }); +}); diff --git a/test/api/index.js b/test/api/index.js index b8ddce7ce8..1f3ae503b9 100644 --- a/test/api/index.js +++ b/test/api/index.js @@ -9,4 +9,5 @@ describe('hljs', function() { require('./starters'); require('./getLanguage'); require('./highlight'); + require('./fixmarkup'); });