diff --git a/lib/parser_block.js b/lib/parser_block.js index 723d25b..63028f9 100644 --- a/lib/parser_block.js +++ b/lib/parser_block.js @@ -89,6 +89,7 @@ ParserBlock.prototype.tokenize = function (state, startLine, endLine) { var TABS_SCAN_RE = /[\n\t]/g; var NEWLINES_RE = /\r[\n\u0085]|[\u2424\u2028\u0085]/g; var SPACES_RE = /\u00a0/g; +var NULL_RE = /\u0000/g; ParserBlock.prototype.parse = function (src, options, env, outTokens) { var state, lineStart = 0, lastTabPos = 0; @@ -101,6 +102,9 @@ ParserBlock.prototype.parse = function (src, options, env, outTokens) { // Normalize newlines src = src.replace(NEWLINES_RE, '\n'); + // Strin NULL characters + src = src.replace(NULL_RE, ''); + // Replace tabs with proper number of spaces (1..4) if (src.indexOf('\t') >= 0) { src = src.replace(TABS_SCAN_RE, function (match, offset) { diff --git a/test/misc.js b/test/misc.js index 5ec5e85..4217724 100644 --- a/test/misc.js +++ b/test/misc.js @@ -164,6 +164,12 @@ describe('API', function () { describe('Misc', function () { + it('Should strip (or replace) NULL characters', function () { + var md = markdownit(); + + assert.strictEqual(md.render('foo\u0000bar'), '

foobar

\n'); + }); + it('Should correctly parse strings without tailing \\n', function () { var md = markdownit();