-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #329 from AnzhiZhang/main
Add data to DefaultUrlSanitizer protocols
- Loading branch information
Showing
2 changed files
with
36 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,13 +93,47 @@ public void sanitizedUrlsShouldSetRelNoFollow() { | |
assertEquals("<p><a rel=\"nofollow\" href=\"https://google.com\"></a></p>\n", sanitizeUrlsRenderer().render(paragraph)); | ||
} | ||
|
||
@Test | ||
public void sanitizedUrlsShouldAllowSafeProtocols() { | ||
Paragraph paragraph = new Paragraph(); | ||
Link link = new Link(); | ||
link.setDestination("http://google.com"); | ||
paragraph.appendChild(link); | ||
assertEquals("<p><a rel=\"nofollow\" href=\"http://google.com\"></a></p>\n", sanitizeUrlsRenderer().render(paragraph)); | ||
|
||
paragraph = new Paragraph(); | ||
link = new Link(); | ||
link.setDestination("https://google.com"); | ||
paragraph.appendChild(link); | ||
assertEquals("<p><a rel=\"nofollow\" href=\"https://google.com\"></a></p>\n", sanitizeUrlsRenderer().render(paragraph)); | ||
|
||
paragraph = new Paragraph(); | ||
link = new Link(); | ||
link.setDestination("mailto:[email protected]"); | ||
paragraph.appendChild(link); | ||
assertEquals("<p><a rel=\"nofollow\" href=\"mailto:[email protected]\"></a></p>\n", sanitizeUrlsRenderer().render(paragraph)); | ||
|
||
String image = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAAQSURBVBhXY/iPBVBf8P9/AG8TY51nJdgkAAAAAElFTkSuQmCC"; | ||
paragraph = new Paragraph(); | ||
link = new Link(); | ||
link.setDestination(image); | ||
paragraph.appendChild(link); | ||
assertEquals("<p><a rel=\"nofollow\" href=\"" + image + "\"></a></p>\n", sanitizeUrlsRenderer().render(paragraph)); | ||
} | ||
|
||
@Test | ||
public void sanitizedUrlsShouldFilterDangerousProtocols() { | ||
Paragraph paragraph = new Paragraph(); | ||
Link link = new Link(); | ||
link.setDestination("javascript:alert(5);"); | ||
paragraph.appendChild(link); | ||
assertEquals("<p><a rel=\"nofollow\" href=\"\"></a></p>\n", sanitizeUrlsRenderer().render(paragraph)); | ||
|
||
paragraph = new Paragraph(); | ||
link = new Link(); | ||
link.setDestination("ftp://google.com"); | ||
paragraph.appendChild(link); | ||
assertEquals("<p><a rel=\"nofollow\" href=\"\"></a></p>\n", sanitizeUrlsRenderer().render(paragraph)); | ||
} | ||
|
||
@Test | ||
|