mirror of
https://github.com/miniflux/v2.git
synced 2025-07-17 17:08:36 +00:00
Add support for protocol relative YouTube URLs
This commit is contained in:
parent
6d0dc451e4
commit
de1a4aad30
2 changed files with 12 additions and 1 deletions
|
@ -17,7 +17,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
youtubeEmbedRegex = regexp.MustCompile(`http[s]?://www\.youtube\.com/embed/(.*)`)
|
youtubeEmbedRegex = regexp.MustCompile(`//www\.youtube\.com/embed/(.*)`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sanitize returns safe HTML.
|
// Sanitize returns safe HTML.
|
||||||
|
@ -291,6 +291,7 @@ func isBlacklistedResource(src string) bool {
|
||||||
|
|
||||||
func isValidIframeSource(src string) bool {
|
func isValidIframeSource(src string) bool {
|
||||||
whitelist := []string{
|
whitelist := []string{
|
||||||
|
"//www.youtube.com",
|
||||||
"http://www.youtube.com",
|
"http://www.youtube.com",
|
||||||
"https://www.youtube.com",
|
"https://www.youtube.com",
|
||||||
"https://www.youtube-nocookie.com",
|
"https://www.youtube-nocookie.com",
|
||||||
|
|
|
@ -203,6 +203,16 @@ 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"></iframe>`
|
||||||
|
output := Sanitize("http://example.org/", input)
|
||||||
|
|
||||||
|
if expected != output {
|
||||||
|
t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestReplaceIframeURL(t *testing.T) {
|
func TestReplaceIframeURL(t *testing.T) {
|
||||||
input := `<iframe src="https://player.vimeo.com/video/123456?title=0&byline=0"></iframe>`
|
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" sandbox="allow-scripts allow-same-origin"></iframe>`
|
expected := `<iframe src="https://player.vimeo.com/video/123456?title=0&byline=0" sandbox="allow-scripts allow-same-origin"></iframe>`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue