Skip to content

Commit 7023826

Browse files
committed
Fix escapes in autolinks
1 parent 791402d commit 7023826

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/handle/link.js

+5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ function link(node, _, context) {
1414
var exit
1515
var value
1616
var subexit
17+
var currentStack
1718

1819
if (formatLinkAsAutolink(node)) {
20+
// Hide the fact that we’re in phrasing, because escapes don’t work.
21+
currentStack = context.stack
22+
context.stack = []
1923
exit = context.enter('autolink')
2024
value = '<' + phrasing(node, context, {before: '<', after: '>'}) + '>'
2125
exit()
26+
context.stack = currentStack
2227
return value
2328
}
2429

test.js

+15
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,21 @@ test('link', function (t) {
13791379
'should use an autolink for nodes w/ a value similar to the url and a protocol (email)'
13801380
)
13811381

1382+
t.deepEqual(
1383+
to({
1384+
type: 'paragraph',
1385+
children: [
1386+
{
1387+
type: 'link',
1388+
url: 'mailto:[email protected]',
1389+
children: [{type: 'text', value: '[email protected]'}]
1390+
}
1391+
]
1392+
}),
1393+
1394+
'should not escape in autolinks'
1395+
)
1396+
13821397
t.equal(
13831398
to({type: 'link', title: 'b'}, {quote: "'"}),
13841399
"[](<> 'b')",

0 commit comments

Comments
 (0)