Skip to content

Commit 857caa4

Browse files
committed
Fix to remove non-terminated character references
Related-to: remarkjs/remark#913.
1 parent 5bd2e1e commit 857caa4

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

complex-types.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type {PhrasingContent, BlockContent} from 'mdast'
33

44
type DirectiveAttributes = Record<string, string>
55

6+
/* eslint-disable @typescript-eslint/consistent-type-definitions */
7+
68
interface DirectiveFields {
79
name: string
810
attributes?: DirectiveAttributes
@@ -33,3 +35,5 @@ declare module 'mdast' {
3335
leafDirective: LeafDirective
3436
}
3537
}
38+
39+
/* eslint-enable @typescript-eslint/consistent-type-definitions */

index.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,35 @@ function exitAttributeIdValue(token) {
154154
const list = /** @type {Array.<[string, string]>} */ (
155155
this.getData('directiveAttributes')
156156
)
157-
list.push(['id', parseEntities(this.sliceSerialize(token))])
157+
list.push([
158+
'id',
159+
parseEntities(this.sliceSerialize(token), {
160+
attribute: true
161+
})
162+
])
158163
}
159164

160165
/** @type {FromMarkdownHandle} */
161166
function exitAttributeClassValue(token) {
162167
const list = /** @type {Array.<[string, string]>} */ (
163168
this.getData('directiveAttributes')
164169
)
165-
list.push(['class', parseEntities(this.sliceSerialize(token))])
170+
list.push([
171+
'class',
172+
parseEntities(this.sliceSerialize(token), {
173+
attribute: true
174+
})
175+
])
166176
}
167177

168178
/** @type {FromMarkdownHandle} */
169179
function exitAttributeValue(token) {
170180
const list = /** @type {Array.<[string, string]>} */ (
171181
this.getData('directiveAttributes')
172182
)
173-
list[list.length - 1][1] = parseEntities(this.sliceSerialize(token))
183+
list[list.length - 1][1] = parseEntities(this.sliceSerialize(token), {
184+
attribute: true
185+
})
174186
}
175187

176188
/** @type {FromMarkdownHandle} */

test.js

+27
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,33 @@ test('markdown -> mdast', (t) => {
197197
'should support attributes'
198198
)
199199

200+
t.deepEqual(
201+
removePosition(
202+
fromMarkdown(':a{b=&param c="&param" d=\'&param\'}', {
203+
extensions: [directive()],
204+
mdastExtensions: [directiveFromMarkdown]
205+
}),
206+
true
207+
),
208+
{
209+
type: 'root',
210+
children: [
211+
{
212+
type: 'paragraph',
213+
children: [
214+
{
215+
type: 'textDirective',
216+
name: 'a',
217+
attributes: {b: '&param', c: '&param', d: '&param'},
218+
children: []
219+
}
220+
]
221+
}
222+
]
223+
},
224+
'should not support non-terminated character references'
225+
)
226+
200227
t.deepEqual(
201228
removePosition(
202229
fromMarkdown(':a{b\nc="d\ne"}', {

0 commit comments

Comments
 (0)