Skip to content

Commit 04e04b1

Browse files
committed
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: <p>Link: [constructor][].</p> With this change, it now renders as expected: <p>Link: <a href="https://example.org/">constructor</a>.</p>
1 parent 666e455 commit 04e04b1

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

lib/marked.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ block.pedantic = merge({}, block.normal, {
135135

136136
function Lexer(options) {
137137
this.tokens = [];
138-
this.tokens.links = {};
138+
this.tokens.links = Object.create(null);
139139
this.options = options || marked.defaults;
140140
this.rules = block.normal;
141141

test/specs/marked/marked-spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ describe('Marked Code spans', function() {
4747
});
4848
});
4949

50+
describe('Marked Links', function() {
51+
var section = 'Links';
52+
53+
var shouldPassButFails = [];
54+
55+
var willNotBeAttemptedByCoreTeam = [];
56+
57+
var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);
58+
59+
markedSpec.forEach(function(spec) {
60+
messenger.test(spec, section, ignore);
61+
});
62+
});
63+
5064
describe('Marked Table cells', function() {
5165
var section = 'Table cells';
5266

test/specs/marked/marked.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,11 @@
5252
"markdown": "|1|2|\n|-|-|\n| |2|",
5353
"html": "<table><thead><tr><th>1</th><th>2</th></tr></thead><tbody><tr><td></td><td>2</td></tr></tbody></table>",
5454
"example": 9
55+
},
56+
{
57+
"section": "Links",
58+
"markdown": "Link: [constructor][].\n\n[constructor]: https://example.org/",
59+
"html": "<p>Link: <a href=\"https://example.org/\">constructor</a>.</p>",
60+
"example": 10
5561
}
5662
]

0 commit comments

Comments
 (0)