Skip to content

Commit

Permalink
Properly close Youtube iframes
Browse files Browse the repository at this point in the history
The HTML standard only allows for specific tags that can be empty and
self-closing. Tags like <script> and <iframe> are not in that list.
While the browser renderer will let these slide, Javascript libraries
like Bootstrap and jQuery might break things because, per spec, the
iframe tag can't be self closing.
  • Loading branch information
t27duck committed Jun 17, 2016
1 parent be03557 commit 5bf0ad6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/bb-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ module BBRuby
'YouTube' => [
/\[youtube\](.*?)\?v=([\w\d\-]+).*?\[\/youtube\]/im,
# '<object width="400" height="330"><param name="movie" value="http://www.youtube.com/v/\2"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/\2" type="application/x-shockwave-flash" wmode="transparent" width="400" height="330"></embed></object>',
'<iframe id="ytplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/\2" frameborder="0"/>',
'<iframe id="ytplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/\2" frameborder="0"></iframe>',
'Display a video from YouTube.com',
'[youtube]http://youtube.com/watch?v=E4Fbk52Mk1w[/youtube]',
:video],
'YouTube (Alternative)' => [
/\[youtube\](.*?)\/v\/([\w\d\-]+)\[\/youtube\]/im,
# '<object width="400" height="330"><param name="movie" value="http://www.youtube.com/v/\2"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/\2" type="application/x-shockwave-flash" wmode="transparent" width="400" height="330"></embed></object>',
'<iframe id="ytplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/\2" frameborder="0"/>',
'<iframe id="ytplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/\2" frameborder="0"></iframe>',
'Display a video from YouTube.com (alternative format)',
'[youtube]http://youtube.com/watch/v/E4Fbk52Mk1w[/youtube]',
:video],
Expand Down
4 changes: 2 additions & 2 deletions test/bb-ruby_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def test_image_link
def test_youtube
# Uncomment below if using 4:3 format youtube video embed
# assert_equal assert_equal '<iframe id="ytplayer" type="text/html" width="320" height="265" src="http://www.youtube.com/embed/E4Fbk52Mk1w" frameborder="0"/>', '[youtube]http://youtube.com/watch?v=E4Fbk52Mk1w[/youtube]'.bbcode_to_html
assert_equal '<iframe id="ytplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/E4Fbk52Mk1w" frameborder="0"/>', '[youtube]http://youtube.com/watch?v=E4Fbk52Mk1w[/youtube]'.bbcode_to_html
assert_equal '<iframe id="ytplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/E4Fbk52Mk1w" frameborder="0"/><iframe id="ytplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/abc123" frameborder="0"/>', '[youtube]http://youtube.com/watch?v=E4Fbk52Mk1w[/youtube][youtube]http://youtube.com/watch?v=abc123[/youtube]'.bbcode_to_html
assert_equal '<iframe id="ytplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/E4Fbk52Mk1w" frameborder="0"></iframe>', '[youtube]http://youtube.com/watch?v=E4Fbk52Mk1w[/youtube]'.bbcode_to_html
assert_equal '<iframe id="ytplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/E4Fbk52Mk1w" frameborder="0"></iframe><iframe id="ytplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/abc123" frameborder="0"></iframe>', '[youtube]http://youtube.com/watch?v=E4Fbk52Mk1w[/youtube][youtube]http://youtube.com/watch?v=abc123[/youtube]'.bbcode_to_html
end

def test_vimeo
Expand Down

0 comments on commit 5bf0ad6

Please sign in to comment.