Skip to content

Commit 1bf35f8

Browse files
committed
Update dev-dependencies
1 parent 5473a15 commit 1bf35f8

File tree

5 files changed

+89
-81
lines changed

5 files changed

+89
-81
lines changed

lib/index.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ const own = {}.hasOwnProperty
226226
*/
227227
export function sanitize(node, options) {
228228
/** @type {Nodes} */
229-
let ctx = {type: 'root', children: []}
229+
let result = {type: 'root', children: []}
230230

231231
/** @type {State} */
232232
const state = {
@@ -238,16 +238,16 @@ export function sanitize(node, options) {
238238
if (replace) {
239239
if (Array.isArray(replace)) {
240240
if (replace.length === 1) {
241-
ctx = replace[0]
241+
result = replace[0]
242242
} else {
243-
ctx.children = replace
243+
result.children = replace
244244
}
245245
} else {
246-
ctx = replace
246+
result = replace
247247
}
248248
}
249249

250-
return ctx
250+
return result
251251
}
252252

253253
/**
@@ -356,7 +356,7 @@ function element(state, unsafe) {
356356
const content = /** @type {Array<ElementContent>} */ (
357357
children(state, unsafe.children)
358358
)
359-
const props = properties(state, unsafe.properties)
359+
const properties_ = properties(state, unsafe.properties)
360360

361361
state.stack.pop()
362362

@@ -395,7 +395,7 @@ function element(state, unsafe) {
395395
const node = {
396396
type: 'element',
397397
tagName: name,
398-
properties: props,
398+
properties: properties_,
399399
children: content
400400
}
401401

@@ -501,17 +501,18 @@ function properties(state, properties) {
501501
: undefined
502502
const defaults =
503503
attributes && own.call(attributes, '*') ? attributes['*'] : undefined
504-
const props = /** @type {Readonly<Record<string, Readonly<unknown>>>} */ (
505-
properties && typeof properties === 'object' ? properties : {}
506-
)
504+
const properties_ =
505+
/** @type {Readonly<Record<string, Readonly<unknown>>>} */ (
506+
properties && typeof properties === 'object' ? properties : {}
507+
)
507508
/** @type {Properties} */
508509
const result = {}
509510
/** @type {string} */
510511
let key
511512

512-
for (key in props) {
513-
if (own.call(props, key)) {
514-
const unsafe = props[key]
513+
for (key in properties_) {
514+
if (own.call(properties_, key)) {
515+
const unsafe = properties_[key]
515516
let safe = propertyValue(
516517
state,
517518
findDefinition(specific, key),

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,28 @@
3636
],
3737
"dependencies": {
3838
"@types/hast": "^3.0.0",
39-
"@ungap/structured-clone": "^1.2.0",
39+
"@ungap/structured-clone": "^1.0.0",
4040
"unist-util-position": "^5.0.0"
4141
},
4242
"devDependencies": {
43-
"@types/node": "^20.0.0",
44-
"@types/ungap__structured-clone": "^0.3.0",
43+
"@types/node": "^22.0.0",
44+
"@types/ungap__structured-clone": "^1.0.0",
4545
"aria-attributes": "^2.0.0",
46-
"c8": "^8.0.0",
46+
"c8": "^10.0.0",
4747
"deepmerge": "^4.0.0",
4848
"hast-util-from-html": "^2.0.0",
4949
"hast-util-to-html": "^9.0.0",
50-
"hastscript": "^8.0.0",
50+
"hastscript": "^9.0.0",
5151
"html-element-attributes": "^3.0.0",
5252
"html-tag-names": "^2.0.0",
5353
"prettier": "^3.0.0",
54-
"remark-cli": "^11.0.0",
55-
"remark-preset-wooorm": "^9.0.0",
54+
"remark-cli": "^12.0.0",
55+
"remark-preset-wooorm": "^10.0.0",
5656
"type-coverage": "^2.0.0",
5757
"typescript": "^5.0.0",
5858
"unist-builder": "^4.0.0",
5959
"unist-util-visit": "^5.0.0",
60-
"xo": "^0.56.0"
60+
"xo": "^0.59.0"
6161
},
6262
"scripts": {
6363
"prepack": "npm run build && npm run format",
@@ -106,6 +106,7 @@
106106
"prettier": true,
107107
"rules": {
108108
"complexity": "off",
109+
"logical-assignment-operators": "off",
109110
"unicorn/prefer-at": "off"
110111
}
111112
}

readme.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212

1313
## Contents
1414

15-
* [What is this?](#what-is-this)
16-
* [When should I use this?](#when-should-i-use-this)
17-
* [Install](#install)
18-
* [Use](#use)
19-
* [API](#api)
20-
* [`defaultSchema`](#defaultschema)
21-
* [`sanitize(tree[, options])`](#sanitizetree-options)
22-
* [`Schema`](#schema)
23-
* [Types](#types)
24-
* [Compatibility](#compatibility)
25-
* [Security](#security)
26-
* [Related](#related)
27-
* [Contribute](#contribute)
28-
* [License](#license)
15+
* [What is this?](#what-is-this)
16+
* [When should I use this?](#when-should-i-use-this)
17+
* [Install](#install)
18+
* [Use](#use)
19+
* [API](#api)
20+
* [`defaultSchema`](#defaultschema)
21+
* [`sanitize(tree[, options])`](#sanitizetree-options)
22+
* [`Schema`](#schema)
23+
* [Types](#types)
24+
* [Compatibility](#compatibility)
25+
* [Security](#security)
26+
* [Related](#related)
27+
* [Contribute](#contribute)
28+
* [License](#license)
2929

3030
## What is this?
3131

@@ -132,11 +132,11 @@ Sanitize a tree.
132132

133133
###### Parameters
134134

135-
* `tree` ([`Node`][node])
136-
— unsafe tree
137-
* `options` ([`Schema`][api-schema], default:
138-
[`defaultSchema`][api-default-schema])
139-
— configuration
135+
* `tree` ([`Node`][node])
136+
— unsafe tree
137+
* `options` ([`Schema`][api-schema], default:
138+
[`defaultSchema`][api-default-schema])
139+
— configuration
140140

141141
###### Returns
142142

@@ -386,8 +386,8 @@ be unsafe (but is fine if you do trust it).
386386

387387
## Related
388388

389-
* [`rehype-sanitize`](https://github.com/rehypejs/rehype-sanitize)
390-
— rehype plugin
389+
* [`rehype-sanitize`](https://github.com/rehypejs/rehype-sanitize)
390+
— rehype plugin
391391

392392
## Contribute
393393

test/baseline.js

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ allAttributes = new Set([...allAttributes].sort())
5858

5959
for (const name of htmlTagNames) {
6060
/** @type {Record<string, string>} */
61-
const props = {}
61+
const properties_ = {}
6262

6363
for (const attribute of allAttributes) {
64-
props[attribute] = 'x'
64+
properties_[attribute] = 'x'
6565
}
6666

67-
delete props.type
67+
delete properties_.type
6868

6969
if (root.children.length > 0) {
7070
root.children.push({type: 'text', value: '\n\n'})
7171
}
7272

73-
let element = h(name, props, [])
73+
let element = h(name, properties_, [])
7474

7575
if (Object.hasOwn(schemaAncestors, name)) {
7676
const ancestor = schemaAncestors[name][0]
@@ -152,30 +152,30 @@ visit(tree, function (node) {
152152
)
153153

154154
/** @type {string} */
155-
let prop
155+
let property
156156

157-
for (prop in node.properties) {
158-
if (Object.hasOwn(node.properties, prop)) {
159-
let value = node.properties[prop]
157+
for (property in node.properties) {
158+
if (Object.hasOwn(node.properties, property)) {
159+
let value = node.properties[property]
160160

161-
if (prop === 'dir' && value === 'auto') {
161+
if (property === 'dir' && value === 'auto') {
162162
continue
163163
}
164164

165165
if (
166166
node.tagName === 'img' &&
167-
prop === 'style' &&
167+
property === 'style' &&
168168
value === 'max-width: 100%;'
169169
) {
170170
continue
171171
}
172172

173-
propertyNamesSeen.add(prop)
173+
propertyNamesSeen.add(property)
174174

175175
assert(
176-
entries.has(prop),
176+
entries.has(property),
177177
'property `' +
178-
prop +
178+
property +
179179
'` was found in GH response (on `' +
180180
node.tagName +
181181
'`) but not defined in `schema.attributes` (global or specific to the element)'
@@ -187,9 +187,9 @@ visit(tree, function (node) {
187187

188188
if (value === 'user-content-x') {
189189
assert(
190-
schemaClobber.includes(prop),
190+
schemaClobber.includes(property),
191191
'property `' +
192-
prop +
192+
property +
193193
'` was found in GH response (on `' +
194194
node.tagName +
195195
'`) with a clobber prefix, but not defined in `schema.clobber`'
@@ -204,36 +204,42 @@ visit(tree, function (node) {
204204
// Value GH sets it to with a clobber prefix.
205205
value === 'user-content-x' ||
206206
// Wrapper for images.
207-
(node.tagName === 'a' && prop === 'target' && value === '_blank') ||
208-
(node.tagName === 'a' && prop === 'rel' && value === 'noopener') ||
207+
(node.tagName === 'a' &&
208+
property === 'target' &&
209+
value === '_blank') ||
210+
(node.tagName === 'a' &&
211+
property === 'rel' &&
212+
value === 'noopener') ||
209213
// Footnotes.
210214
(node.tagName === 'a' &&
211-
prop === 'ariaDescribedBy' &&
215+
property === 'ariaDescribedBy' &&
212216
value === 'footnote-label') ||
213217
(node.tagName === 'a' &&
214-
prop === 'href' &&
218+
property === 'href' &&
215219
String(value).startsWith('x-')) ||
216220
(node.tagName === 'a' &&
217-
prop === 'id' &&
221+
property === 'id' &&
218222
String(value).startsWith('user-content-x-')) ||
219223
(node.tagName === 'a' &&
220-
prop === 'className' &&
224+
property === 'className' &&
221225
value === 'data-footnote-backref') ||
222226
(node.tagName === 'section' &&
223-
prop === 'className' &&
227+
property === 'className' &&
224228
value === 'footnotes') ||
225229
(node.tagName === 'h2' &&
226-
prop === 'id' &&
230+
property === 'id' &&
227231
(value === 'footnote-label' ||
228232
value === 'user-content-footnote-label')) ||
229-
(node.tagName === 'h2' && prop === 'className' && value === 'sr-only')
233+
(node.tagName === 'h2' &&
234+
property === 'className' &&
235+
value === 'sr-only')
230236
) {
231237
continue
232238
}
233239

234240
console.log(
235241
'Unexpected key `%s` (`%s`) on <%s>',
236-
prop,
242+
property,
237243
value,
238244
node.tagName
239245
)

test/index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ test('`text`', async function (t) {
192192
})
193193

194194
await t.test('should ignore `text` in `script` elements', async function () {
195-
assert.equal(toHtml(sanitize(h('script', u('text', 'alert(1)')))), '')
195+
assert.equal(toHtml(sanitize(h('script', {}, u('text', 'alert(1)')))), '')
196196
})
197197

198198
await t.test('should show `text` in `style` elements', async function () {
199199
assert.equal(
200-
toHtml(sanitize(h('style', u('text', 'alert(1)')))),
200+
toHtml(sanitize(h('style', {}, u('text', 'alert(1)')))),
201201
'alert(1)'
202202
)
203203
})
@@ -236,7 +236,7 @@ test('`element`', async function (t) {
236236

237237
await t.test('should ignore unknown elements', async function () {
238238
assert.deepEqual(
239-
sanitize(h('unknown', u('text', 'alert(1)'))),
239+
sanitize(h('unknown', {}, u('text', 'alert(1)'))),
240240
u('text', 'alert(1)')
241241
)
242242
})
@@ -860,36 +860,36 @@ function toString() {
860860
}
861861

862862
/**
863-
* Test `valid` and `invalid` `url`s in `prop` on `tagName`.
863+
* Test `valid` and `invalid` `url`s in `property` on `tagName`.
864864
*
865865
* @param {string} tagName
866-
* @param {string} prop
866+
* @param {string} property
867867
* @param {{valid: Record<string, string>, invalid: Record<string, string>}} all
868868
*/
869-
function testAllUrls(tagName, prop, all) {
870-
testUrls(tagName, prop, all.valid, true)
871-
testUrls(tagName, prop, all.invalid, false)
869+
function testAllUrls(tagName, property, all) {
870+
testUrls(tagName, property, all.valid, true)
871+
testUrls(tagName, property, all.invalid, false)
872872
}
873873

874874
/**
875-
* Test `valid` `url`s in `prop` on `tagName`.
875+
* Test `valid` `url`s in `property` on `tagName`.
876876
*
877877
* @param {string} tagName
878-
* @param {string} prop
878+
* @param {string} property
879879
* @param {Record<string, string>} urls
880880
* @param {boolean} valid
881881
*/
882-
function testUrls(tagName, prop, urls, valid) {
882+
function testUrls(tagName, property, urls, valid) {
883883
/** @type {string} */
884884
let name
885885

886886
for (name in urls) {
887887
if (own.call(urls, name)) {
888-
const props = {[prop]: urls[name]}
888+
const properties_ = {[property]: urls[name]}
889889

890890
assert.deepEqual(
891-
sanitize(h(tagName, props)),
892-
h(tagName, valid ? props : {}),
891+
sanitize(h(tagName, properties_)),
892+
h(tagName, valid ? properties_ : {}),
893893
'should ' + (valid ? 'allow' : 'clean') + ' ' + name
894894
)
895895
}

0 commit comments

Comments
 (0)