Skip to content

Commit

Permalink
Fix control character in definition destination
Browse files Browse the repository at this point in the history
Closes GH-47
  • Loading branch information
wooorm committed Nov 23, 2021
1 parent 2953253 commit a57b805
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/handle/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function definition(node, _, context) {
if (
// If there’s no url, or…
!node.url ||
// If there’s whitespace, enclosed is prettier.
/[ \t\r\n]/.test(node.url)
// If there are control characters or whitespace.
/[\0- \u007F]/.test(node.url)
) {
subexit = context.enter('destinationLiteral')
value += '<' + safe(context, node.url, {before: '<', after: '>'}) + '>'
Expand Down
2 changes: 1 addition & 1 deletion lib/util/format-link-as-autolink.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function formatLinkAsAutolink(node, context) {
// And that starts w/ a protocol…
/^[a-z][a-z+.-]+:/i.test(node.url) &&
// And that doesn’t contain ASCII control codes (character escapes and
// references don’t work) or angle brackets…
// references don’t work), space, or angle brackets…
!/[\0- <>\u007F]/.test(node.url)
)
}
14 changes: 10 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,12 @@ test('definition', (t) => {
'should encode a line ending in `url` in an enclosed url'
)

t.equal(
to({type: 'definition', identifier: 'a', url: '\f'}),
'[a]: <\f>\n',
'should encode a line ending in `url` in an enclosed url'
)

t.equal(
to({type: 'definition', identifier: 'a', url: 'b(c'}),
'[a]: b\\(c\n',
Expand Down Expand Up @@ -3646,8 +3652,8 @@ a *\\** is this emphasis? *\\**`
tree = from(doc)

t.deepEqual(
removePosition(tree, true),
removePosition(from(to(tree)), true),
removePosition(tree, true),
'should roundtrip asterisks (tree)'
)

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

t.deepEqual(
removePosition(tree, true),
removePosition(from(to(tree)), true),
removePosition(tree, true),
'should roundtrip underscores (tree)'
)

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

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

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

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

t.end()
})

0 comments on commit a57b805

Please sign in to comment.