Skip to content

Commit 0ff62a4

Browse files
committed
Rename allowDangerousHTML > allowDangerousHtml
1 parent 91f9eba commit 0ff62a4

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

lib/index.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ module.exports = toHtml
1111
var quotationMark = '"'
1212
var apostrophe = "'"
1313

14+
var deprecationWarningIssued = false
15+
1416
function toHtml(node, options) {
1517
var settings = options || {}
1618
var quote = settings.quote || quotationMark
@@ -29,6 +31,15 @@ function toHtml(node, options) {
2931
)
3032
}
3133

34+
if (settings.allowDangerousHTML !== undefined) {
35+
if (!deprecationWarningIssued) {
36+
deprecationWarningIssued = true
37+
console.warn(
38+
'Deprecation warning: `allowDangerousHTML` is a nonstandard option, use `allowDangerousHtml` instead'
39+
)
40+
}
41+
}
42+
3243
return one(
3344
{
3445
valid: settings.allowParseErrors ? 0 : 1,
@@ -44,7 +55,7 @@ function toHtml(node, options) {
4455
tightLists: settings.tightCommaSeparatedLists,
4556
tightClose: settings.tightSelfClosing,
4657
collapseEmpty: settings.collapseEmptyAttributes,
47-
dangerous: settings.allowDangerousHTML,
58+
dangerous: settings.allowDangerousHtml || settings.allowDangerousHTML,
4859
voids: settings.voids || voids.concat(),
4960
entities: settings.entities || {},
5061
close: settings.closeSelfClosing,

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Do not encode some characters which cause XSS vulnerabilities in older browsers
166166
(`boolean`, default: `false`).
167167
**Note**: Only set this if you completely trust the content.
168168

169-
###### `options.allowDangerousHTML`
169+
###### `options.allowDangerousHtml`
170170

171171
Allow `raw` nodes and insert them as raw HTML.
172172
When falsey, encodes `raw` nodes (`boolean`, default: `false`).

test/raw.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,21 @@ test('`element`', function(t) {
1111
'should encode `raw`s'
1212
)
1313

14+
t.deepEqual(
15+
to(u('raw', '<script>alert("XSS!")</script>'), {allowDangerousHtml: true}),
16+
'<script>alert("XSS!")</script>',
17+
'should not encode `raw`s in `allowDangerousHtml` mode'
18+
)
19+
20+
t.deepEqual(
21+
to(u('raw', '<script>alert("XSS!")</script>'), {allowDangerousHTML: true}),
22+
'<script>alert("XSS!")</script>',
23+
'should support the legacy `allowDangerousHTML` (#1)'
24+
)
1425
t.deepEqual(
1526
to(u('raw', '<script>alert("XSS!")</script>'), {allowDangerousHTML: true}),
1627
'<script>alert("XSS!")</script>',
17-
'should not encode `raw`s in `allowDangerousHTML` mode'
28+
'should support the legacy `allowDangerousHTML` (#2)'
1829
)
1930

2031
t.end()

types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ declare namespace hastUtilToHtml {
164164
*
165165
* @defaultValue false
166166
*/
167-
allowDangerousHTML: boolean
167+
allowDangerousHtml: boolean
168168
}
169169
}
170170

types/tests.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ toHtml(node, {
6969
allowDangerousCharacters: true
7070
})
7171
toHtml(node, {
72-
allowDangerousHTML: true
72+
allowDangerousHtml: true
7373
})

0 commit comments

Comments
 (0)