mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
refactor: unexport symbols
This commit is contained in:
parent
a4d51b5586
commit
566670cc06
36 changed files with 369 additions and 376 deletions
|
@ -27,7 +27,7 @@ func BenchmarkSanitize(b *testing.B) {
|
|||
}
|
||||
for b.Loop() {
|
||||
for _, v := range testCases {
|
||||
SanitizeHTMLWithDefaultOptions(v[0], v[1])
|
||||
sanitizeHTMLWithDefaultOptions(v[0], v[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ func FuzzSanitizer(f *testing.F) {
|
|||
i++
|
||||
}
|
||||
|
||||
out := SanitizeHTMLWithDefaultOptions("", orig)
|
||||
out := sanitizeHTMLWithDefaultOptions("", orig)
|
||||
|
||||
tok = html.NewTokenizer(strings.NewReader(out))
|
||||
j := 0
|
||||
|
@ -56,7 +56,7 @@ func FuzzSanitizer(f *testing.F) {
|
|||
|
||||
func TestValidInput(t *testing.T) {
|
||||
input := `<p>This is a <strong>text</strong> with an image: <img src="http://example.org/" alt="Test" loading="lazy">.</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if input != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, input, output)
|
||||
|
@ -66,7 +66,7 @@ func TestValidInput(t *testing.T) {
|
|||
func TestImgWithWidthAndHeightAttribute(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" width="10" height="20">`
|
||||
expected := `<img src="https://example.org/image.png" width="10" height="20" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
|
@ -76,7 +76,7 @@ func TestImgWithWidthAndHeightAttribute(t *testing.T) {
|
|||
func TestImgWithWidthAttributeLargerThanMinifluxLayout(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" width="1200" height="675">`
|
||||
expected := `<img src="https://example.org/image.png" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
|
@ -86,7 +86,7 @@ func TestImgWithWidthAttributeLargerThanMinifluxLayout(t *testing.T) {
|
|||
func TestImgWithIncorrectWidthAndHeightAttribute(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" width="10px" height="20px">`
|
||||
expected := `<img src="https://example.org/image.png" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
|
@ -96,7 +96,7 @@ func TestImgWithIncorrectWidthAndHeightAttribute(t *testing.T) {
|
|||
func TestImgWithIncorrectWidthAttribute(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" width="10px" height="20">`
|
||||
expected := `<img src="https://example.org/image.png" height="20" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
|
@ -106,7 +106,7 @@ func TestImgWithIncorrectWidthAttribute(t *testing.T) {
|
|||
func TestImgWithEmptyWidthAndHeightAttribute(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" width="" height="">`
|
||||
expected := `<img src="https://example.org/image.png" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
|
@ -116,7 +116,7 @@ func TestImgWithEmptyWidthAndHeightAttribute(t *testing.T) {
|
|||
func TestImgWithIncorrectHeightAttribute(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" width="10" height="20px">`
|
||||
expected := `<img src="https://example.org/image.png" width="10" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
|
@ -126,7 +126,7 @@ func TestImgWithIncorrectHeightAttribute(t *testing.T) {
|
|||
func TestImgWithNegativeWidthAttribute(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" width="-10" height="20">`
|
||||
expected := `<img src="https://example.org/image.png" height="20" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
|
@ -136,7 +136,7 @@ func TestImgWithNegativeWidthAttribute(t *testing.T) {
|
|||
func TestImgWithNegativeHeightAttribute(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" width="10" height="-20">`
|
||||
expected := `<img src="https://example.org/image.png" width="10" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
|
@ -146,7 +146,7 @@ func TestImgWithNegativeHeightAttribute(t *testing.T) {
|
|||
func TestImgWithTextDataURL(t *testing.T) {
|
||||
input := `<img src="data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==" alt="Example">`
|
||||
expected := ``
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
|
@ -156,7 +156,7 @@ func TestImgWithTextDataURL(t *testing.T) {
|
|||
func TestImgWithDataURL(t *testing.T) {
|
||||
input := `<img src="data:image/gif;base64,test" alt="Example">`
|
||||
expected := `<img src="data:image/gif;base64,test" alt="Example" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
|
@ -166,7 +166,7 @@ func TestImgWithDataURL(t *testing.T) {
|
|||
func TestImgWithSrcsetAttribute(t *testing.T) {
|
||||
input := `<img srcset="example-320w.jpg, example-480w.jpg 1.5x, example-640w.jpg 2x, example-640w.jpg 640w" src="example-640w.jpg" alt="Example">`
|
||||
expected := `<img srcset="http://example.org/example-320w.jpg, http://example.org/example-480w.jpg 1.5x, http://example.org/example-640w.jpg 2x, http://example.org/example-640w.jpg 640w" src="http://example.org/example-640w.jpg" alt="Example" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
|
@ -176,7 +176,7 @@ func TestImgWithSrcsetAttribute(t *testing.T) {
|
|||
func TestImgWithSrcsetAndNoSrcAttribute(t *testing.T) {
|
||||
input := `<img srcset="example-320w.jpg, example-480w.jpg 1.5x, example-640w.jpg 2x, example-640w.jpg 640w" alt="Example">`
|
||||
expected := `<img srcset="http://example.org/example-320w.jpg, http://example.org/example-480w.jpg 1.5x, http://example.org/example-640w.jpg 2x, http://example.org/example-640w.jpg 640w" alt="Example" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
|
@ -203,7 +203,7 @@ func TestImgWithFetchPriorityAttribute(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", tc.input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", tc.input)
|
||||
if output != tc.expected {
|
||||
t.Errorf(`Wrong output for input %q: expected %q, got %q`, tc.input, tc.expected, output)
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ func TestImgWithFetchPriorityAttribute(t *testing.T) {
|
|||
func TestImgWithInvalidFetchPriorityAttribute(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" fetchpriority="invalid">`
|
||||
expected := `<img src="https://example.org/image.png" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: expected %q, got %q`, expected, output)
|
||||
|
@ -223,7 +223,7 @@ func TestImgWithInvalidFetchPriorityAttribute(t *testing.T) {
|
|||
func TestNonImgWithFetchPriorityAttribute(t *testing.T) {
|
||||
input := `<p fetchpriority="high">Text</p>`
|
||||
expected := `<p>Text</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: expected %q, got %q`, expected, output)
|
||||
|
@ -250,7 +250,7 @@ func TestImgWithDecodingAttribute(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", tc.input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", tc.input)
|
||||
if output != tc.expected {
|
||||
t.Errorf(`Wrong output for input %q: expected %q, got %q`, tc.input, tc.expected, output)
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ func TestImgWithDecodingAttribute(t *testing.T) {
|
|||
func TestImgWithInvalidDecodingAttribute(t *testing.T) {
|
||||
input := `<img src="https://example.org/image.png" decoding="invalid">`
|
||||
expected := `<img src="https://example.org/image.png" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: expected %q, got %q`, expected, output)
|
||||
|
@ -270,7 +270,7 @@ func TestImgWithInvalidDecodingAttribute(t *testing.T) {
|
|||
func TestNonImgWithDecodingAttribute(t *testing.T) {
|
||||
input := `<p decoding="async">Text</p>`
|
||||
expected := `<p>Text</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: expected %q, got %q`, expected, output)
|
||||
|
@ -280,7 +280,7 @@ func TestNonImgWithDecodingAttribute(t *testing.T) {
|
|||
func TestSourceWithSrcsetAndMedia(t *testing.T) {
|
||||
input := `<picture><source media="(min-width: 800px)" srcset="elva-800w.jpg"></picture>`
|
||||
expected := `<picture><source media="(min-width: 800px)" srcset="http://example.org/elva-800w.jpg"></picture>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
|
@ -290,7 +290,7 @@ func TestSourceWithSrcsetAndMedia(t *testing.T) {
|
|||
func TestMediumImgWithSrcset(t *testing.T) {
|
||||
input := `<img alt="Image for post" class="t u v ef aj" src="https://miro.medium.com/max/5460/1*aJ9JibWDqO81qMfNtqgqrw.jpeg" srcset="https://miro.medium.com/max/552/1*aJ9JibWDqO81qMfNtqgqrw.jpeg 276w, https://miro.medium.com/max/1000/1*aJ9JibWDqO81qMfNtqgqrw.jpeg 500w" sizes="500px" width="2730" height="3407">`
|
||||
expected := `<img alt="Image for post" src="https://miro.medium.com/max/5460/1*aJ9JibWDqO81qMfNtqgqrw.jpeg" srcset="https://miro.medium.com/max/552/1*aJ9JibWDqO81qMfNtqgqrw.jpeg 276w, https://miro.medium.com/max/1000/1*aJ9JibWDqO81qMfNtqgqrw.jpeg 500w" sizes="500px" loading="lazy">`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf(`Wrong output: %s`, output)
|
||||
|
@ -299,7 +299,7 @@ func TestMediumImgWithSrcset(t *testing.T) {
|
|||
|
||||
func TestSelfClosingTags(t *testing.T) {
|
||||
input := `<p>This <br> is a <strong>text</strong> <br/>with an image: <img src="http://example.org/" alt="Test" loading="lazy"/>.</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if input != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, input, output)
|
||||
|
@ -308,7 +308,7 @@ func TestSelfClosingTags(t *testing.T) {
|
|||
|
||||
func TestTable(t *testing.T) {
|
||||
input := `<table><tr><th>A</th><th colspan="2">B</th></tr><tr><td>C</td><td>D</td><td>E</td></tr></table>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if input != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, input, output)
|
||||
|
@ -318,7 +318,7 @@ func TestTable(t *testing.T) {
|
|||
func TestRelativeURL(t *testing.T) {
|
||||
input := `This <a href="/test.html">link is relative</a> and this image: <img src="../folder/image.png"/>`
|
||||
expected := `This <a href="http://example.org/test.html" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">link is relative</a> and this image: <img src="http://example.org/folder/image.png" loading="lazy"/>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -328,7 +328,7 @@ func TestRelativeURL(t *testing.T) {
|
|||
func TestProtocolRelativeURL(t *testing.T) {
|
||||
input := `This <a href="//static.example.org/index.html">link is relative</a>.`
|
||||
expected := `This <a href="https://static.example.org/index.html" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">link is relative</a>.`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -338,7 +338,7 @@ func TestProtocolRelativeURL(t *testing.T) {
|
|||
func TestInvalidTag(t *testing.T) {
|
||||
input := `<p>My invalid <z>tag</z>.</p>`
|
||||
expected := `<p>My invalid tag.</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -348,7 +348,7 @@ func TestInvalidTag(t *testing.T) {
|
|||
func TestVideoTag(t *testing.T) {
|
||||
input := `<p>My valid <video src="videofile.webm" autoplay poster="posterimage.jpg">fallback</video>.</p>`
|
||||
expected := `<p>My valid <video src="http://example.org/videofile.webm" poster="http://example.org/posterimage.jpg" controls>fallback</video>.</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -358,7 +358,7 @@ func TestVideoTag(t *testing.T) {
|
|||
func TestAudioAndSourceTag(t *testing.T) {
|
||||
input := `<p>My music <audio controls="controls"><source src="foo.wav" type="audio/wav"></audio>.</p>`
|
||||
expected := `<p>My music <audio controls><source src="http://example.org/foo.wav" type="audio/wav"></audio>.</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -368,7 +368,7 @@ func TestAudioAndSourceTag(t *testing.T) {
|
|||
func TestUnknownTag(t *testing.T) {
|
||||
input := `<p>My invalid <unknown>tag</unknown>.</p>`
|
||||
expected := `<p>My invalid tag.</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -378,7 +378,7 @@ func TestUnknownTag(t *testing.T) {
|
|||
func TestInvalidNestedTag(t *testing.T) {
|
||||
input := `<p>My invalid <z>tag with some <em>valid</em> tag</z>.</p>`
|
||||
expected := `<p>My invalid tag with some <em>valid</em> tag.</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -390,7 +390,7 @@ func TestInvalidIFrame(t *testing.T) {
|
|||
|
||||
input := `<iframe src="http://example.org/"></iframe>`
|
||||
expected := ``
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.com/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.com/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -402,7 +402,7 @@ func TestSameDomainIFrame(t *testing.T) {
|
|||
|
||||
input := `<iframe src="http://example.com/test"></iframe>`
|
||||
expected := ``
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.com/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.com/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: %q != %q`, expected, output)
|
||||
|
@ -414,7 +414,7 @@ func TestInvidiousIFrame(t *testing.T) {
|
|||
|
||||
input := `<iframe src="https://yewtu.be/watch?v=video_id"></iframe>`
|
||||
expected := `<iframe src="https://yewtu.be/watch?v=video_id" sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" loading="lazy"></iframe>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.com/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.com/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: %q != %q`, expected, output)
|
||||
|
@ -432,7 +432,7 @@ func TestCustomYoutubeEmbedURL(t *testing.T) {
|
|||
|
||||
input := `<iframe src="https://www.invidious.custom/embed/1234"></iframe>`
|
||||
expected := `<iframe src="https://www.invidious.custom/embed/1234" sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" loading="lazy"></iframe>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.com/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.com/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: %q != %q`, expected, output)
|
||||
|
@ -444,7 +444,7 @@ func TestIFrameWithChildElements(t *testing.T) {
|
|||
|
||||
input := `<iframe src="https://www.youtube.com/"><p>test</p></iframe>`
|
||||
expected := `<iframe src="https://www.youtube.com/" sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" loading="lazy"></iframe>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.com/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.com/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -474,7 +474,7 @@ func TestLinkWithNoTarget(t *testing.T) {
|
|||
func TestAnchorLink(t *testing.T) {
|
||||
input := `<p>This link is <a href="#some-anchor">an anchor</a></p>`
|
||||
expected := `<p>This link is <a href="#some-anchor">an anchor</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -484,7 +484,7 @@ func TestAnchorLink(t *testing.T) {
|
|||
func TestInvalidURLScheme(t *testing.T) {
|
||||
input := `<p>This link is <a src="file:///etc/passwd">not valid</a></p>`
|
||||
expected := `<p>This link is not valid</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -494,7 +494,7 @@ func TestInvalidURLScheme(t *testing.T) {
|
|||
func TestAPTURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="apt:some-package?channel=test">valid</a></p>`
|
||||
expected := `<p>This link is <a href="apt:some-package?channel=test" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -504,7 +504,7 @@ func TestAPTURIScheme(t *testing.T) {
|
|||
func TestBitcoinURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W">valid</a></p>`
|
||||
expected := `<p>This link is <a href="bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -514,7 +514,7 @@ func TestBitcoinURIScheme(t *testing.T) {
|
|||
func TestCallToURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="callto:12345679">valid</a></p>`
|
||||
expected := `<p>This link is <a href="callto:12345679" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -524,7 +524,7 @@ func TestCallToURIScheme(t *testing.T) {
|
|||
func TestFeedURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="feed://example.com/rss.xml">valid</a></p>`
|
||||
expected := `<p>This link is <a href="feed://example.com/rss.xml" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -532,7 +532,7 @@ func TestFeedURIScheme(t *testing.T) {
|
|||
|
||||
input = `<p>This link is <a href="feed:https://example.com/rss.xml">valid</a></p>`
|
||||
expected = `<p>This link is <a href="feed:https://example.com/rss.xml" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output = SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output = sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -542,7 +542,7 @@ func TestFeedURIScheme(t *testing.T) {
|
|||
func TestGeoURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="geo:13.4125,103.8667">valid</a></p>`
|
||||
expected := `<p>This link is <a href="geo:13.4125,103.8667" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -552,7 +552,7 @@ func TestGeoURIScheme(t *testing.T) {
|
|||
func TestItunesURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="itms://itunes.com/apps/my-app-name">valid</a></p>`
|
||||
expected := `<p>This link is <a href="itms://itunes.com/apps/my-app-name" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -560,7 +560,7 @@ func TestItunesURIScheme(t *testing.T) {
|
|||
|
||||
input = `<p>This link is <a href="itms-apps://itunes.com/apps/my-app-name">valid</a></p>`
|
||||
expected = `<p>This link is <a href="itms-apps://itunes.com/apps/my-app-name" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output = SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output = sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -570,7 +570,7 @@ func TestItunesURIScheme(t *testing.T) {
|
|||
func TestMagnetURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="magnet:?xt.1=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C&xt.2=urn:sha1:TXGCZQTH26NL6OUQAJJPFALHG2LTGBC7">valid</a></p>`
|
||||
expected := `<p>This link is <a href="magnet:?xt.1=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C&xt.2=urn:sha1:TXGCZQTH26NL6OUQAJJPFALHG2LTGBC7" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -580,7 +580,7 @@ func TestMagnetURIScheme(t *testing.T) {
|
|||
func TestMailtoURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="mailto:jsmith@example.com?subject=A%20Test&body=My%20idea%20is%3A%20%0A">valid</a></p>`
|
||||
expected := `<p>This link is <a href="mailto:jsmith@example.com?subject=A%20Test&body=My%20idea%20is%3A%20%0A" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -590,7 +590,7 @@ func TestMailtoURIScheme(t *testing.T) {
|
|||
func TestNewsURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="news://news.server.example/*">valid</a></p>`
|
||||
expected := `<p>This link is <a href="news://news.server.example/*" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -598,7 +598,7 @@ func TestNewsURIScheme(t *testing.T) {
|
|||
|
||||
input = `<p>This link is <a href="news:example.group.this">valid</a></p>`
|
||||
expected = `<p>This link is <a href="news:example.group.this" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output = SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output = sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -606,7 +606,7 @@ func TestNewsURIScheme(t *testing.T) {
|
|||
|
||||
input = `<p>This link is <a href="nntp://news.server.example/example.group.this">valid</a></p>`
|
||||
expected = `<p>This link is <a href="nntp://news.server.example/example.group.this" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output = SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output = sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -616,7 +616,7 @@ func TestNewsURIScheme(t *testing.T) {
|
|||
func TestRTMPURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="rtmp://mycompany.com/vod/mp4:mycoolvideo.mov">valid</a></p>`
|
||||
expected := `<p>This link is <a href="rtmp://mycompany.com/vod/mp4:mycoolvideo.mov" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -626,7 +626,7 @@ func TestRTMPURIScheme(t *testing.T) {
|
|||
func TestSIPURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="sip:+1-212-555-1212:1234@gateway.com;user=phone">valid</a></p>`
|
||||
expected := `<p>This link is <a href="sip:+1-212-555-1212:1234@gateway.com;user=phone" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -634,7 +634,7 @@ func TestSIPURIScheme(t *testing.T) {
|
|||
|
||||
input = `<p>This link is <a href="sips:alice@atlanta.com?subject=project%20x&priority=urgent">valid</a></p>`
|
||||
expected = `<p>This link is <a href="sips:alice@atlanta.com?subject=project%20x&priority=urgent" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output = SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output = sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -644,7 +644,7 @@ func TestSIPURIScheme(t *testing.T) {
|
|||
func TestSkypeURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="skype:echo123?call">valid</a></p>`
|
||||
expected := `<p>This link is <a href="skype:echo123?call" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -654,7 +654,7 @@ func TestSkypeURIScheme(t *testing.T) {
|
|||
func TestSpotifyURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="spotify:track:2jCnn1QPQ3E8ExtLe6INsx">valid</a></p>`
|
||||
expected := `<p>This link is <a href="spotify:track:2jCnn1QPQ3E8ExtLe6INsx" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -664,7 +664,7 @@ func TestSpotifyURIScheme(t *testing.T) {
|
|||
func TestSteamURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="steam://settings/account">valid</a></p>`
|
||||
expected := `<p>This link is <a href="steam://settings/account" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -674,7 +674,7 @@ func TestSteamURIScheme(t *testing.T) {
|
|||
func TestSubversionURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="svn://example.org">valid</a></p>`
|
||||
expected := `<p>This link is <a href="svn://example.org" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -682,7 +682,7 @@ func TestSubversionURIScheme(t *testing.T) {
|
|||
|
||||
input = `<p>This link is <a href="svn+ssh://example.org">valid</a></p>`
|
||||
expected = `<p>This link is <a href="svn+ssh://example.org" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output = SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output = sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -692,7 +692,7 @@ func TestSubversionURIScheme(t *testing.T) {
|
|||
func TestTelURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="tel:+1-201-555-0123">valid</a></p>`
|
||||
expected := `<p>This link is <a href="tel:+1-201-555-0123" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -702,7 +702,7 @@ func TestTelURIScheme(t *testing.T) {
|
|||
func TestWebcalURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="webcal://example.com/calendar.ics">valid</a></p>`
|
||||
expected := `<p>This link is <a href="webcal://example.com/calendar.ics" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -712,7 +712,7 @@ func TestWebcalURIScheme(t *testing.T) {
|
|||
func TestXMPPURIScheme(t *testing.T) {
|
||||
input := `<p>This link is <a href="xmpp:user@host?subscribe&type=subscribed">valid</a></p>`
|
||||
expected := `<p>This link is <a href="xmpp:user@host?subscribe&type=subscribed" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">valid</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -722,7 +722,7 @@ func TestXMPPURIScheme(t *testing.T) {
|
|||
func TestBlacklistedLink(t *testing.T) {
|
||||
input := `<p>This image is not valid <img src="https://stats.wordpress.com/some-tracker"></p>`
|
||||
expected := `<p>This image is not valid </p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -732,7 +732,7 @@ func TestBlacklistedLink(t *testing.T) {
|
|||
func TestLinkWithTrackers(t *testing.T) {
|
||||
input := `<p>This link has trackers <a href="https://example.com/page?utm_source=newsletter">Test</a></p>`
|
||||
expected := `<p>This link has trackers <a href="https://example.com/page" rel="noopener noreferrer" referrerpolicy="no-referrer" target="_blank">Test</a></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -742,7 +742,7 @@ func TestLinkWithTrackers(t *testing.T) {
|
|||
func TestImageSrcWithTrackers(t *testing.T) {
|
||||
input := `<p>This image has trackers <img src="https://example.org/?id=123&utm_source=newsletter&utm_medium=email&fbclid=abc123"></p>`
|
||||
expected := `<p>This image has trackers <img src="https://example.org/?id=123" loading="lazy"></p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -752,7 +752,7 @@ func TestImageSrcWithTrackers(t *testing.T) {
|
|||
func Test1x1PixelTracker(t *testing.T) {
|
||||
input := `<p><img src="https://tracker1.example.org/" height="1" width="1"> and <img src="https://tracker2.example.org/" height="1" width="1"/></p>`
|
||||
expected := `<p> and </p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -762,7 +762,7 @@ func Test1x1PixelTracker(t *testing.T) {
|
|||
func Test0x0PixelTracker(t *testing.T) {
|
||||
input := `<p><img src="https://tracker1.example.org/" height="0" width="0"> and <img src="https://tracker2.example.org/" height="0" width="0"/></p>`
|
||||
expected := `<p> and </p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -772,7 +772,7 @@ func Test0x0PixelTracker(t *testing.T) {
|
|||
func TestXmlEntities(t *testing.T) {
|
||||
input := `<pre>echo "test" > /etc/hosts</pre>`
|
||||
expected := `<pre>echo "test" > /etc/hosts</pre>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -782,7 +782,7 @@ func TestXmlEntities(t *testing.T) {
|
|||
func TestEspaceAttributes(t *testing.T) {
|
||||
input := `<td rowspan="<b>test</b>">test</td>`
|
||||
expected := `<td rowspan="<b>test</b>">test</td>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -792,7 +792,7 @@ func TestEspaceAttributes(t *testing.T) {
|
|||
func TestReplaceYoutubeURL(t *testing.T) {
|
||||
input := `<iframe src="http://www.youtube.com/embed/test123?version=3&rel=1&fs=1&autohide=2&showsearch=0&showinfo=1&iv_load_policy=1&wmode=transparent"></iframe>`
|
||||
expected := `<iframe src="https://www.youtube-nocookie.com/embed/test123?version=3&rel=1&fs=1&autohide=2&showsearch=0&showinfo=1&iv_load_policy=1&wmode=transparent" sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" loading="lazy"></iframe>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -802,7 +802,7 @@ func TestReplaceYoutubeURL(t *testing.T) {
|
|||
func TestReplaceSecureYoutubeURL(t *testing.T) {
|
||||
input := `<iframe src="https://www.youtube.com/embed/test123"></iframe>`
|
||||
expected := `<iframe src="https://www.youtube-nocookie.com/embed/test123" sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" loading="lazy"></iframe>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -812,7 +812,7 @@ func TestReplaceSecureYoutubeURL(t *testing.T) {
|
|||
func TestReplaceSecureYoutubeURLWithParameters(t *testing.T) {
|
||||
input := `<iframe src="https://www.youtube.com/embed/test123?rel=0&controls=0"></iframe>`
|
||||
expected := `<iframe src="https://www.youtube-nocookie.com/embed/test123?rel=0&controls=0" sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" loading="lazy"></iframe>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -822,7 +822,7 @@ func TestReplaceSecureYoutubeURLWithParameters(t *testing.T) {
|
|||
func TestReplaceYoutubeURLAlreadyReplaced(t *testing.T) {
|
||||
input := `<iframe src="https://www.youtube-nocookie.com/embed/test123?rel=0&controls=0" sandbox="allow-scripts allow-same-origin"></iframe>`
|
||||
expected := `<iframe src="https://www.youtube-nocookie.com/embed/test123?rel=0&controls=0" sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" loading="lazy"></iframe>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -832,7 +832,7 @@ func TestReplaceYoutubeURLAlreadyReplaced(t *testing.T) {
|
|||
func TestReplaceProtocolRelativeYoutubeURL(t *testing.T) {
|
||||
input := `<iframe src="//www.youtube.com/embed/Bf2W84jrGqs" width="560" height="314" allowfullscreen="allowfullscreen"></iframe>`
|
||||
expected := `<iframe src="https://www.youtube-nocookie.com/embed/Bf2W84jrGqs" width="560" height="314" allowfullscreen="allowfullscreen" sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" loading="lazy"></iframe>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -851,7 +851,7 @@ func TestReplaceYoutubeURLWithCustomURL(t *testing.T) {
|
|||
|
||||
input := `<iframe src="https://www.youtube.com/embed/test123?version=3&rel=1&fs=1&autohide=2&showsearch=0&showinfo=1&iv_load_policy=1&wmode=transparent"></iframe>`
|
||||
expected := `<iframe src="https://invidious.custom/embed/test123?version=3&rel=1&fs=1&autohide=2&showsearch=0&showinfo=1&iv_load_policy=1&wmode=transparent" sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" loading="lazy"></iframe>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -861,7 +861,7 @@ func TestReplaceYoutubeURLWithCustomURL(t *testing.T) {
|
|||
func TestVimeoIframeRewriteWithQueryString(t *testing.T) {
|
||||
input := `<iframe src="https://player.vimeo.com/video/123456?title=0&byline=0"></iframe>`
|
||||
expected := `<iframe src="https://player.vimeo.com/video/123456?title=0&byline=0&dnt=1" sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" loading="lazy"></iframe>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: %q != %q`, expected, output)
|
||||
|
@ -871,7 +871,7 @@ func TestVimeoIframeRewriteWithQueryString(t *testing.T) {
|
|||
func TestVimeoIframeRewriteWithoutQueryString(t *testing.T) {
|
||||
input := `<iframe src="https://player.vimeo.com/video/123456"></iframe>`
|
||||
expected := `<iframe src="https://player.vimeo.com/video/123456?dnt=1" sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" loading="lazy"></iframe>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: %q != %q`, expected, output)
|
||||
|
@ -881,7 +881,7 @@ func TestVimeoIframeRewriteWithoutQueryString(t *testing.T) {
|
|||
func TestReplaceNoScript(t *testing.T) {
|
||||
input := `<p>Before paragraph.</p><noscript>Inside <code>noscript</code> tag with an image: <img src="http://example.org/" alt="Test" loading="lazy"></noscript><p>After paragraph.</p>`
|
||||
expected := `<p>Before paragraph.</p><p>After paragraph.</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -891,7 +891,7 @@ func TestReplaceNoScript(t *testing.T) {
|
|||
func TestReplaceScript(t *testing.T) {
|
||||
input := `<p>Before paragraph.</p><script type="text/javascript">alert("1");</script><p>After paragraph.</p>`
|
||||
expected := `<p>Before paragraph.</p><p>After paragraph.</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -901,7 +901,7 @@ func TestReplaceScript(t *testing.T) {
|
|||
func TestReplaceStyle(t *testing.T) {
|
||||
input := `<p>Before paragraph.</p><style>body { background-color: #ff0000; }</style><p>After paragraph.</p>`
|
||||
expected := `<p>Before paragraph.</p><p>After paragraph.</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -911,7 +911,7 @@ func TestReplaceStyle(t *testing.T) {
|
|||
func TestHiddenParagraph(t *testing.T) {
|
||||
input := `<p>Before paragraph.</p><p hidden>This should <em>not</em> appear in the <strong>output</strong></p><p>After paragraph.</p>`
|
||||
expected := `<p>Before paragraph.</p><p>After paragraph.</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -922,7 +922,7 @@ func TestAttributesAreStripped(t *testing.T) {
|
|||
input := `<p style="color: red;">Some text.<hr style="color: blue"/>Test.</p>`
|
||||
expected := `<p>Some text.<hr/>Test.</p>`
|
||||
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
}
|
||||
|
@ -931,7 +931,7 @@ func TestAttributesAreStripped(t *testing.T) {
|
|||
func TestMathML(t *testing.T) {
|
||||
input := `<math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>x</mi><mn>2</mn></msup></math>`
|
||||
expected := `<math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>x</mi><mn>2</mn></msup></math>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -941,7 +941,7 @@ func TestMathML(t *testing.T) {
|
|||
func TestInvalidMathMLXMLNamespace(t *testing.T) {
|
||||
input := `<math xmlns="http://example.org"><msup><mi>x</mi><mn>2</mn></msup></math>`
|
||||
expected := `<math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>x</mi><mn>2</mn></msup></math>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -951,7 +951,7 @@ func TestInvalidMathMLXMLNamespace(t *testing.T) {
|
|||
func TestBlockedResourcesSubstrings(t *testing.T) {
|
||||
input := `<p>Before paragraph.</p><img src="http://stats.wordpress.com/something.php" alt="Blocked Resource"><p>After paragraph.</p>`
|
||||
expected := `<p>Before paragraph.</p><p>After paragraph.</p>`
|
||||
output := SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -959,7 +959,7 @@ func TestBlockedResourcesSubstrings(t *testing.T) {
|
|||
|
||||
input = `<p>Before paragraph.</p><img src="http://twitter.com/share?text=This+is+google+a+search+engine&url=https%3A%2F%2Fwww.google.com" alt="Blocked Resource"><p>After paragraph.</p>`
|
||||
expected = `<p>Before paragraph.</p><p>After paragraph.</p>`
|
||||
output = SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output = sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
@ -967,7 +967,7 @@ func TestBlockedResourcesSubstrings(t *testing.T) {
|
|||
|
||||
input = `<p>Before paragraph.</p><img src="http://www.facebook.com/sharer.php?u=https%3A%2F%2Fwww.google.com%[title]=This+Is%2C+Google+a+search+engine" alt="Blocked Resource"><p>After paragraph.</p>`
|
||||
expected = `<p>Before paragraph.</p><p>After paragraph.</p>`
|
||||
output = SanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
output = sanitizeHTMLWithDefaultOptions("http://example.org/", input)
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue