From 407d202720192b885f3527442d8bdf8c55a927fa Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 28 Jun 2018 13:13:06 -0700 Subject: [PATCH] fix issues link references and prototypes Link with names that clashed with properties inherited from the Object prototype (such as "constructor") were not expanding. This fixes this issue. Before this change, markdown of this form...: Link: [constructor][]. [constructor]: https://example.org/ ...resulted in HTML output of this form:

Link: [constructor][].

With this change, it now renders as expected:

Link: constructor.

--- lib/marked.js | 2 +- test/specs/marked/marked-spec.js | 14 ++++++++++++++ test/specs/marked/marked.json | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/marked.js b/lib/marked.js index 81c482d41c7..ca608845b50 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -135,7 +135,7 @@ block.pedantic = merge({}, block.normal, { function Lexer(options) { this.tokens = []; - this.tokens.links = {}; + this.tokens.links = Object.create(null); this.options = options || marked.defaults; this.rules = block.normal; diff --git a/test/specs/marked/marked-spec.js b/test/specs/marked/marked-spec.js index 5d4d32e91c7..bec0b6c88a4 100644 --- a/test/specs/marked/marked-spec.js +++ b/test/specs/marked/marked-spec.js @@ -47,6 +47,20 @@ describe('Marked Code spans', function() { }); }); +describe('Marked Links', function() { + var section = 'Links'; + + var shouldPassButFails = []; + + var willNotBeAttemptedByCoreTeam = []; + + var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam); + + markedSpec.forEach(function(spec) { + messenger.test(spec, section, ignore); + }); +}); + describe('Marked Table cells', function() { var section = 'Table cells'; diff --git a/test/specs/marked/marked.json b/test/specs/marked/marked.json index 60c2023827f..3153756383b 100644 --- a/test/specs/marked/marked.json +++ b/test/specs/marked/marked.json @@ -5,6 +5,12 @@ "html": "

someone@example.com

", "example": 1 }, + { + "section": "Links", + "markdown": "Link: [constructor][].\n\n[constructor]: https://example.org/", + "html": "

Link: constructor.

", + "example": 10 + }, { "section": "Table cells", "markdown": "|1|\n|-|\n|1|",