Skip to content

Commit

Permalink
Rename allowDangerousHTML > allowDangerousHtml
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jan 16, 2020
1 parent 91f9eba commit 0ff62a4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
13 changes: 12 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module.exports = toHtml
var quotationMark = '"'
var apostrophe = "'"

var deprecationWarningIssued = false

function toHtml(node, options) {
var settings = options || {}
var quote = settings.quote || quotationMark
Expand All @@ -29,6 +31,15 @@ function toHtml(node, options) {
)
}

if (settings.allowDangerousHTML !== undefined) {
if (!deprecationWarningIssued) {
deprecationWarningIssued = true
console.warn(
'Deprecation warning: `allowDangerousHTML` is a nonstandard option, use `allowDangerousHtml` instead'
)
}
}

return one(
{
valid: settings.allowParseErrors ? 0 : 1,
Expand All @@ -44,7 +55,7 @@ function toHtml(node, options) {
tightLists: settings.tightCommaSeparatedLists,
tightClose: settings.tightSelfClosing,
collapseEmpty: settings.collapseEmptyAttributes,
dangerous: settings.allowDangerousHTML,
dangerous: settings.allowDangerousHtml || settings.allowDangerousHTML,
voids: settings.voids || voids.concat(),
entities: settings.entities || {},
close: settings.closeSelfClosing,
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Do not encode some characters which cause XSS vulnerabilities in older browsers
(`boolean`, default: `false`).
**Note**: Only set this if you completely trust the content.

###### `options.allowDangerousHTML`
###### `options.allowDangerousHtml`

Allow `raw` nodes and insert them as raw HTML.
When falsey, encodes `raw` nodes (`boolean`, default: `false`).
Expand Down
13 changes: 12 additions & 1 deletion test/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@ test('`element`', function(t) {
'should encode `raw`s'
)

t.deepEqual(
to(u('raw', '<script>alert("XSS!")</script>'), {allowDangerousHtml: true}),
'<script>alert("XSS!")</script>',
'should not encode `raw`s in `allowDangerousHtml` mode'
)

t.deepEqual(
to(u('raw', '<script>alert("XSS!")</script>'), {allowDangerousHTML: true}),
'<script>alert("XSS!")</script>',
'should support the legacy `allowDangerousHTML` (#1)'
)
t.deepEqual(
to(u('raw', '<script>alert("XSS!")</script>'), {allowDangerousHTML: true}),
'<script>alert("XSS!")</script>',
'should not encode `raw`s in `allowDangerousHTML` mode'
'should support the legacy `allowDangerousHTML` (#2)'
)

t.end()
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ declare namespace hastUtilToHtml {
*
* @defaultValue false
*/
allowDangerousHTML: boolean
allowDangerousHtml: boolean
}
}

Expand Down
2 changes: 1 addition & 1 deletion types/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ toHtml(node, {
allowDangerousCharacters: true
})
toHtml(node, {
allowDangerousHTML: true
allowDangerousHtml: true
})

0 comments on commit 0ff62a4

Please sign in to comment.