Skip to content

Commit d82e19a

Browse files
committed
Fix escapes
1 parent 437f5a2 commit d82e19a

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/unsafe.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ module.exports = [
3838
{atBreak: true, character: '#'},
3939
// Dollar sign and percentage are not used in markdown.
4040
// An ampersand could start a character reference.
41-
{atBreak: true, character: '&', after: '[#A-Za-z]'},
41+
{character: '&', after: '[#A-Za-z]'},
4242
// An apostrophe can break out of a title.
4343
{character: "'", inConstruct: 'titleApostrophe'},
4444
// A left paren could break out of a destination raw.
4545
{character: '(', inConstruct: 'destinationRaw'},
46+
{before: '\\]', character: '(', inConstruct: 'phrasing'},
4647
// A right paren could start a list item or break out of a destination
4748
// raw.
4849
{atBreak: true, before: '\\d+', character: ')'},
@@ -91,7 +92,8 @@ module.exports = [
9192
// Caret is not used in markdown for constructs.
9293
// An underscore can start emphasis, strong, or a thematic break.
9394
{atBreak: true, character: '_'},
94-
{character: '_', inConstruct: 'phrasing'},
95+
{before: '[^A-Za-z]', character: '_', inConstruct: 'phrasing'},
96+
{character: '_', after: '[^A-Za-z]', inConstruct: 'phrasing'},
9597
// A grave accent can start code (fenced or text), or it can break out of
9698
// a grave accent code fence.
9799
{atBreak: true, character: '`'},

test.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ test('imageReference', function (t) {
11561156
identifier: '&b;',
11571157
referenceType: 'full'
11581158
}),
1159-
'![&a;][&b;]',
1159+
'![\\&a;][\\&b;]',
11601160
'should support incorrect character references'
11611161
)
11621162

@@ -1514,7 +1514,7 @@ test('linkReference', function (t) {
15141514
identifier: '&b;',
15151515
referenceType: 'full'
15161516
}),
1517-
'[&a;][&b;]',
1517+
'[\\&a;][\\&b;]',
15181518
'should support incorrect character references'
15191519
)
15201520

@@ -1549,6 +1549,18 @@ test('linkReference', function (t) {
15491549
'should use a full reference if w/o `referenceType` and the label does not match the reference'
15501550
)
15511551

1552+
t.equal(
1553+
to({
1554+
type: 'paragraph',
1555+
children: [
1556+
{type: 'linkReference', children: [{type: 'text', value: 'a'}]},
1557+
{type: 'text', value: '(b)'}
1558+
]
1559+
}),
1560+
'[a][]\\(b)',
1561+
'should use a full reference if w/o `referenceType` and the label does not match the reference'
1562+
)
1563+
15521564
t.end()
15531565
})
15541566

@@ -2345,7 +2357,7 @@ test('escape', function (t) {
23452357

23462358
t.equal(
23472359
to({type: 'paragraph', children: [{type: 'text', value: '![](a.jpg)'}]}),
2348-
'\\!\\[](a.jpg)',
2360+
'\\!\\[]\\(a.jpg)',
23492361
'should escape what would otherwise be an image (resource)'
23502362
)
23512363

@@ -2357,7 +2369,7 @@ test('escape', function (t) {
23572369

23582370
t.equal(
23592371
to({type: 'paragraph', children: [{type: 'text', value: '[](a.jpg)'}]}),
2360-
'\\[](a.jpg)',
2372+
'\\[]\\(a.jpg)',
23612373
'should escape what would otherwise be a link (resource)'
23622374
)
23632375

0 commit comments

Comments
 (0)