add NoopenerLinks (#437)
Liming Jin jinliming2@gmail.com
Sat, 26 May 2018 15:57:26 +0800
2 files changed,
19 insertions(+),
4 deletions(-)
M
html.go
→
html.go
@@ -35,6 +35,7 @@ SkipLinks // Skip all links
Safelink // Only link to trusted protocols NofollowLinks // Only link with rel="nofollow" NoreferrerLinks // Only link with rel="noreferrer" + NoopenerLinks // Only link with rel="noopener" HrefTargetBlank // Add a blank target CompletePage // Generate a complete HTML page UseXHTML // Generate XHTML output instead of HTML@@ -285,6 +286,9 @@ val = append(val, "nofollow")
} if flags&NoreferrerLinks != 0 { val = append(val, "noreferrer") + } + if flags&NoopenerLinks != 0 { + val = append(val, "noopener") } if flags&HrefTargetBlank != 0 { attrs = append(attrs, "target=\"_blank\"")
M
inline_test.go
→
inline_test.go
@@ -497,15 +497,26 @@ doTestsInlineParam(t, noreferrerTests, TestParams{
HTMLFlags: Safelink | NoreferrerLinks, }) - var nofollownoreferrerTests = []string{ + var noopenerTests = []string{ + "[foo](http://bar.com/foo/)\n", + "<p><a href=\"http://bar.com/foo/\" rel=\"noopener\">foo</a></p>\n", + + "[foo](/bar/)\n", + "<p><a href=\"/bar/\">foo</a></p>\n", + } + doTestsInlineParam(t, noopenerTests, TestParams{ + HTMLFlags: Safelink | NoopenerLinks, + }) + + var nofollownoreferrernoopenerTests = []string{ "[foo](http://bar.com/foo/)\n", - "<p><a href=\"http://bar.com/foo/\" rel=\"nofollow noreferrer\">foo</a></p>\n", + "<p><a href=\"http://bar.com/foo/\" rel=\"nofollow noreferrer noopener\">foo</a></p>\n", "[foo](/bar/)\n", "<p><a href=\"/bar/\">foo</a></p>\n", } - doTestsInlineParam(t, nofollownoreferrerTests, TestParams{ - HTMLFlags: Safelink | NofollowLinks | NoreferrerLinks, + doTestsInlineParam(t, nofollownoreferrernoopenerTests, TestParams{ + HTMLFlags: Safelink | NofollowLinks | NoreferrerLinks | NoopenerLinks, }) }