Skip to content

Commit a57b805

Browse files
committed
Fix control character in definition destination
Closes GH-47
1 parent 2953253 commit a57b805

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

lib/handle/definition.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export function definition(node, _, context) {
2424
if (
2525
// If there’s no url, or…
2626
!node.url ||
27-
// If there’s whitespace, enclosed is prettier.
28-
/[ \t\r\n]/.test(node.url)
27+
// If there are control characters or whitespace.
28+
/[\0- \u007F]/.test(node.url)
2929
) {
3030
subexit = context.enter('destinationLiteral')
3131
value += '<' + safe(context, node.url, {before: '<', after: '>'}) + '>'

lib/util/format-link-as-autolink.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function formatLinkAsAutolink(node, context) {
2828
// And that starts w/ a protocol…
2929
/^[a-z][a-z+.-]+:/i.test(node.url) &&
3030
// And that doesn’t contain ASCII control codes (character escapes and
31-
// references don’t work) or angle brackets…
31+
// references don’t work), space, or angle brackets…
3232
!/[\0- <>\u007F]/.test(node.url)
3333
)
3434
}

test/index.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,12 @@ test('definition', (t) => {
931931
'should encode a line ending in `url` in an enclosed url'
932932
)
933933

934+
t.equal(
935+
to({type: 'definition', identifier: 'a', url: '\f'}),
936+
'[a]: <\f>\n',
937+
'should encode a line ending in `url` in an enclosed url'
938+
)
939+
934940
t.equal(
935941
to({type: 'definition', identifier: 'a', url: 'b(c'}),
936942
'[a]: b\\(c\n',
@@ -3646,8 +3652,8 @@ a *\\** is this emphasis? *\\**`
36463652
tree = from(doc)
36473653

36483654
t.deepEqual(
3649-
removePosition(tree, true),
36503655
removePosition(from(to(tree)), true),
3656+
removePosition(tree, true),
36513657
'should roundtrip asterisks (tree)'
36523658
)
36533659

@@ -3679,20 +3685,20 @@ a _\\__ is this emphasis? _\\__`
36793685
tree = from(doc)
36803686

36813687
t.deepEqual(
3682-
removePosition(tree, true),
36833688
removePosition(from(to(tree)), true),
3689+
removePosition(tree, true),
36843690
'should roundtrip underscores (tree)'
36853691
)
36863692

36873693
doc = to(from(`(____`))
36883694

3689-
t.equal(doc, to(from(doc)), 'should roundtrip attention-like plain text')
3695+
t.equal(to(from(doc)), doc, 'should roundtrip attention-like plain text')
36903696

36913697
doc = to(
36923698
from('Once activated, a service worker ______, then transitions to idle…')
36933699
)
36943700

3695-
t.equal(doc, to(from(doc)), 'should roundtrip faux “fill in the blank” spans')
3701+
t.equal(to(from(doc)), doc, 'should roundtrip faux “fill in the blank” spans')
36963702

36973703
t.end()
36983704
})

0 commit comments

Comments
 (0)