allow hyphens in YouTube video IDs

This commit is contained in:
Dan Hansen & Sarah Mei 2010-11-25 21:05:54 -08:00
parent 690951dcd1
commit 5075a7384b
2 changed files with 14 additions and 1 deletions

View file

@ -152,7 +152,7 @@ module ApplicationHelper
end end
if options[:youtube] if options[:youtube]
while youtube = message.match(/youtube\.com::([A-Za-z0-9_\\]+)/) while youtube = message.match(/youtube\.com::([A-Za-z0-9_\\\-]+)/)
videoid = youtube[1] videoid = youtube[1]
message.gsub!('youtube.com::'+videoid, '<a class="video-link" data-host="youtube.com" data-video-id="' + videoid + '" href="#video">Youtube: ' + youtube_title(videoid) + '</a>') message.gsub!('youtube.com::'+videoid, '<a class="video-link" data-host="youtube.com" data-video-id="' + videoid + '" href="#video">Youtube: ' + youtube_title(videoid) + '</a>')
end end

View file

@ -84,6 +84,19 @@ describe ApplicationHelper do
res.should =~ /data-host="youtube.com"/ res.should =~ /data-host="youtube.com"/
res.should =~ /data-video-id="#{videoid}"/ res.should =~ /data-video-id="#{videoid}"/
end end
it "recognizes youtube links with hyphens" do
proto="http"
videoid = "ABYnqp-bxvg"
url="www.youtube.com/watch?v="+videoid+"&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
title = "UP & down & UP & down &amp;"
mock_http = mock("http")
Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http)
mock_http.should_receive(:get).with('/feeds/api/videos/'+videoid+'?v=2', nil).and_return([nil, 'Foobar <title>'+title+'</title> hallo welt <asd><dasdd><a>dsd</a>'])
res = markdownify(proto+'://'+url)
res.should =~ /data-host="youtube.com"/
res.should =~ /data-video-id="#{videoid}"/
end
it "recognizes multiple links of different types" do it "recognizes multiple links of different types" do
message = "http:// Hello World, this is for www.joindiaspora.com and not for http://www.google.com though their Youtube service is neat, take http://www.youtube.com/watch?v=foobar or www.youtube.com/watch?foo=bar&v=BARFOO&whatever=related It is a good idea we finally have youtube, so enjoy this video http://www.youtube.com/watch?v=rickrolld" message = "http:// Hello World, this is for www.joindiaspora.com and not for http://www.google.com though their Youtube service is neat, take http://www.youtube.com/watch?v=foobar or www.youtube.com/watch?foo=bar&v=BARFOO&whatever=related It is a good idea we finally have youtube, so enjoy this video http://www.youtube.com/watch?v=rickrolld"