forked from AOEpeople/aoe_technology_radar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved sanitize function into a separate file including some simple tests closes AOEpeople#91
- Loading branch information
1 parent
5a5928f
commit e0113c4
Showing
5 changed files
with
45 additions
and
17 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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { sanitize } from "./sanitize"; | ||
|
||
describe("sanitize", () => { | ||
it("should sanitize the string input to HTML output", () => { | ||
let res = sanitize('foo'); | ||
expect(res.__html).toEqual("foo"); | ||
res = sanitize('<a href="https://example.org">Example.org</a>'); | ||
expect(res.__html).toEqual("<a href=\"https://example.org\">Example.org</a>"); | ||
}); | ||
it("should not sanitize not allowed tags", () => { | ||
let res = sanitize('Before <iframe src="https://example.org"></iframe> After'); | ||
expect(res.__html).toEqual("Before After"); | ||
}); | ||
it("should accept options for rendering", () => { | ||
let res = sanitize('<a href="https://example.org" target="_blank">Example.org</a>', { allowedAttributes: { a: ['href']}}); | ||
expect(res.__html).toEqual("<a href=\"https://example.org\">Example.org</a>"); | ||
}); | ||
}); | ||
|
||
|
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,15 @@ | ||
import sanitizeHtml from 'sanitize-html'; | ||
|
||
const defaultSanitizeOptions = { | ||
allowedTags: ['b', 'i', 'em', 'strong', 'a', 'ul', 'ol', 'li'], | ||
allowedAttributes: { | ||
'a': ['href', 'target'] | ||
} | ||
} | ||
|
||
export const sanitize = (dirty: string, options: sanitizeHtml.IOptions = defaultSanitizeOptions) => ({ | ||
__html: sanitizeHtml( | ||
dirty, | ||
options | ||
) | ||
}); |