Browse Source

Strip NULL characters, according to new spec

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
d8c1b1f7d6
  1. 4
      lib/parser_block.js
  2. 6
      test/misc.js

4
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) {

6
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'), '<p>foobar</p>\n');
});
it('Should correctly parse strings without tailing \\n', function () {
var md = markdownit();

Loading…
Cancel
Save