Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/blog/src/main/Youtube.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ object Youtube:
def augmentEmbeds(html: Html): Html =
addCredentialless(fixStartTimes(html))

private val IframeRegex = """allowfullscreen></iframe>""".r
private val IframeRegex = """(<iframe[^>]*)>""".r
private def addCredentialless(html: Html) = Html:
IframeRegex.replaceAllIn(html.value, """credentialless="credentialless" allowfullscreen></iframe>""")
IframeRegex.replaceAllIn(html.value, """$1 credentialless>""")

private val TimeMarkerRegex = """youtube\.com/watch\?v=[\w-]++\#t=([^"]++)[^?]++\?feature=oembed""".r
private val HourMinSecRegex = """(\d++)h(\d++)m(\d++)s""".r
Expand Down
2 changes: 1 addition & 1 deletion modules/blog/src/test/Fixtures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ object Fixtures:

<h4>Modified Chigorin/Trompowsky </h4>

<div data-oembed="https://www.youtube.com/watch?v=uz-dZ2W4Bf0#t=1m01s" data-oembed-type="video" data-oembed-provider="youtube"><iframe width="480" height="270" src="https://www.youtube.com/embed/uz-dZ2W4Bf0?feature=oembed" frameborder="0" allowfullscreen></iframe></div>
<div data-oembed="https://www.youtube.com/watch?v=uz-dZ2W4Bf0#t=1m01s" data-oembed-type="video" data-oembed-provider="youtube"><iframe width="480" height="270" src="https://www.youtube.com/embed/uz-dZ2W4Bf0?feature=oembed" frameborder="0" allowfullscreen title="Crazyhouse opening repertoire"></iframe></div>

<p><em>Basic setup:</em> 1. d4 ... 2. Nc3 ... 3. Bg5 ... 4. Nf3 ... 5. e3 (or e4, if allowed) ... 6. Be2/d3 ... 7. 0-0</p>

Expand Down
14 changes: 12 additions & 2 deletions modules/blog/src/test/YoutubeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ class YoutubeTest extends munit.FunSuite:
val fixed = Youtube.augmentEmbeds(Fixtures.withYoutube).value
assert(
!fixed.contains(
"""<div data-oembed="https://www.youtube.com/watch?v=uz-dZ2W4Bf0#t=4m14s" data-oembed-type="video" data-oembed-provider="youtube"><iframe width="480" height="270" src="https://www.youtube.com/embed/uz-dZ2W4Bf0?feature=oembed" frameborder="0" credentialless="credentialless" allowfullscreen></iframe></div>"""
"""<div data-oembed="https://www.youtube.com/watch?v=uz-dZ2W4Bf0#t=4m14s" data-oembed-type="video" data-oembed-provider="youtube"><iframe width="480" height="270" src="https://www.youtube.com/embed/uz-dZ2W4Bf0?feature=oembed" frameborder="0" allowfullscreen credentialless></iframe></div>"""
)
)
assert(
fixed.contains(
"""<div data-oembed="https://www.youtube.com/watch?v=uz-dZ2W4Bf0#t=4m14s" data-oembed-type="video" data-oembed-provider="youtube"><iframe width="480" height="270" src="https://www.youtube.com/embed/uz-dZ2W4Bf0?feature=oembed&start=254" frameborder="0" credentialless="credentialless" allowfullscreen></iframe></div>"""
"""<div data-oembed="https://www.youtube.com/watch?v=uz-dZ2W4Bf0#t=4m14s" data-oembed-type="video" data-oembed-provider="youtube"><iframe width="480" height="270" src="https://www.youtube.com/embed/uz-dZ2W4Bf0?feature=oembed&start=254" frameborder="0" allowfullscreen credentialless></iframe></div>"""
)
)
assert(
!fixed.contains(
"""<div data-oembed="https://www.youtube.com/watch?v=uz-dZ2W4Bf0#t=1m01s" data-oembed-type="video" data-oembed-provider="youtube"><iframe width="480" height="270" src="https://www.youtube.com/embed/uz-dZ2W4Bf0?feature=oembed" frameborder="0" allowfullscreen title="Crazyhouse opening repertoire" credentialless></iframe></div>"""
)
)
assert(
fixed.contains(
"""<div data-oembed="https://www.youtube.com/watch?v=uz-dZ2W4Bf0#t=1m01s" data-oembed-type="video" data-oembed-provider="youtube"><iframe width="480" height="270" src="https://www.youtube.com/embed/uz-dZ2W4Bf0?feature=oembed&start=61" frameborder="0" allowfullscreen title="Crazyhouse opening repertoire" credentialless></iframe></div>"""
)
)
}