From 5075a7384be9d5c1335b50cbd72d3d9ee7b1c2b1 Mon Sep 17 00:00:00 2001 From: Dan Hansen & Sarah Mei Date: Thu, 25 Nov 2010 21:05:54 -0800 Subject: [PATCH] allow hyphens in YouTube video IDs --- app/helpers/application_helper.rb | 2 +- spec/helpers/application_helper_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9dbaf49fd..43ea75037 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -152,7 +152,7 @@ module ApplicationHelper end 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] message.gsub!('youtube.com::'+videoid, 'Youtube: ' + youtube_title(videoid) + '') end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index b58357193..8938dfd3d 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -84,6 +84,19 @@ describe ApplicationHelper do res.should =~ /data-host="youtube.com"/ res.should =~ /data-video-id="#{videoid}"/ 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 &" + 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+' hallo welt dsd']) + 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 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"