Skip to content

Commit

Permalink
fix youtube filter: short url with params
Browse files Browse the repository at this point in the history
  • Loading branch information
dejan committed Dec 8, 2011
1 parent 2d60a36 commit 35ff655
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/auto_html/filters/youtube.rb
@@ -1,5 +1,5 @@
AutoHtml.add_filter(:youtube).with(:width => 420, :height => 315, :frameborder => 0, :wmode => nil) do |text, options|
regex = /(https?):\/\/(www.)?(youtube\.com\/watch\?v=|youtu\.be\/)([A-Za-z0-9_-]*)(\&\S+)?/
regex = /(https?):\/\/(www.)?(youtube\.com\/watch\?v=|youtu\.be\/)([A-Za-z0-9_-]*)(\&\S+)?.*/
text.gsub(regex) do
protocol = $1
youtube_id = $4
Expand Down
5 changes: 5 additions & 0 deletions test/unit/filters/youtube_test.rb
Expand Up @@ -36,4 +36,9 @@ def test_transform_https
result = auto_html("https://www.youtube.com/watch?v=t7NdBIA4zJg") { youtube }
assert_equal '<iframe width="420" height="315" src="https://www.youtube.com/embed/t7NdBIA4zJg" frameborder="0" allowfullscreen></iframe>', result
end

def test_short_with_params
result = auto_html("http://youtu.be/t7NdBIA4zJg?t=1s&hd=1") { youtube }
assert_equal '<iframe width="420" height="315" src="http://www.youtube.com/embed/t7NdBIA4zJg" frameborder="0" allowfullscreen></iframe>', result
end
end

0 comments on commit 35ff655

Please sign in to comment.