Skip to content

Commit

Permalink
Do not add "undefined" to the beginning of the result of .fixMarkup()
Browse files Browse the repository at this point in the history
Fixes #1452

- Added default return value (empty string) to the ".replace()" call.
  • Loading branch information
nknapp committed Feb 18, 2017
1 parent 57f97ef commit db5ef50
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ https://highlightjs.org/
} else if (options.tabReplace) {
return p1.replace(/\t/g, options.tabReplace);
}
return '';
});
}

Expand Down
21 changes: 21 additions & 0 deletions test/api/fixmarkup.js
Original file line number Diff line number Diff line change
@@ -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 = '{ <span class="hljs-attr">"some"</span>: \n <span class="hljs-string">"json"</span> }';
const result = hljs.fixMarkup(value);


result.should.equal(
'{ <span class="hljs-attr">"some"</span>: <br> <span class="hljs-string">"json"</span> }'
);
});
});
1 change: 1 addition & 0 deletions test/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ describe('hljs', function() {
require('./starters');
require('./getLanguage');
require('./highlight');
require('./fixmarkup');
});

0 comments on commit db5ef50

Please sign in to comment.