-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
62 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage/ | ||
rehype-sanitize.js | ||
rehype-sanitize.min.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
var clean = require('hast-util-sanitize'); | ||
var clean = require('hast-util-sanitize') | ||
|
||
module.exports = sanitize; | ||
module.exports = sanitize | ||
|
||
function sanitize(options) { | ||
return transformer; | ||
return transformer | ||
function transformer(tree) { | ||
return clean(tree, options); | ||
return clean(tree, options) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,42 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
var test = require('tape'); | ||
var rehype = require('rehype'); | ||
var merge = require('deepmerge'); | ||
var gh = require('hast-util-sanitize/lib/github'); | ||
var sanitize = require('.'); | ||
var test = require('tape') | ||
var rehype = require('rehype') | ||
var merge = require('deepmerge') | ||
var gh = require('hast-util-sanitize/lib/github') | ||
var sanitize = require('.') | ||
|
||
test('sanitize', function (t) { | ||
t.plan(2); | ||
test('sanitize', function(t) { | ||
t.plan(2) | ||
|
||
t.test('should work', function (st) { | ||
var input = '<img onmouseover="alert(\'alpha\')">'; | ||
var output = '<img>'; | ||
t.test('should work', function(st) { | ||
var input = '<img onmouseover="alert(\'alpha\')">' | ||
var output = '<img>' | ||
|
||
st.plan(3); | ||
st.plan(3) | ||
|
||
rehype() | ||
.use(sanitize) | ||
.process(input, function (err, file) { | ||
st.ifErr(err, 'shouldn’t fail'); | ||
st.equal(file.messages.length, 0, 'shouldn’t warn'); | ||
st.equal(String(file), String(output), 'should match'); | ||
}); | ||
}); | ||
.process(input, function(err, file) { | ||
st.ifErr(err, 'shouldn’t fail') | ||
st.equal(file.messages.length, 0, 'shouldn’t warn') | ||
st.equal(String(file), String(output), 'should match') | ||
}) | ||
}) | ||
|
||
t.test('options', function (st) { | ||
var input = '<math><mi xlink:href="data:x,<script>alert(\'echo\')</script>"></mi></math>'; | ||
var output = '<math><mi></mi></math>'; | ||
t.test('options', function(st) { | ||
var input = | ||
'<math><mi xlink:href="data:x,<script>alert(\'echo\')</script>"></mi></math>' | ||
var output = '<math><mi></mi></math>' | ||
|
||
st.plan(3); | ||
st.plan(3) | ||
|
||
rehype() | ||
.use(sanitize, merge(gh, {tagNames: ['math', 'mi']})) | ||
.process(input, function (err, file) { | ||
st.ifErr(err, 'shouldn’t fail'); | ||
st.equal(file.messages.length, 0, 'shouldn’t warn'); | ||
st.equal(String(file), String(output), 'should match'); | ||
}); | ||
}); | ||
}); | ||
.process(input, function(err, file) { | ||
st.ifErr(err, 'shouldn’t fail') | ||
st.equal(file.messages.length, 0, 'shouldn’t warn') | ||
st.equal(String(file), String(output), 'should match') | ||
}) | ||
}) | ||
}) |