diff --git a/app/helpers/markdownify_helper.rb b/app/helpers/markdownify_helper.rb
index 4e0244375..587a50ad1 100644
--- a/app/helpers/markdownify_helper.rb
+++ b/app/helpers/markdownify_helper.rb
@@ -70,7 +70,7 @@ module MarkdownifyHelper
captures = [$1,$2,$3]
if !captures[0].nil?
m
- elsif m.match(/(youtube|vimeo)/)
+ elsif m.match(/(youtu.?be|vimeo)/)
m.gsub(/(\*|_)/) { |m| "\\#{$1}" } #remove markers on markdown chars to not markdown inside links
else
res = %{#{captures[2]}}
diff --git a/spec/helpers/markdownify_helper_spec.rb b/spec/helpers/markdownify_helper_spec.rb
index 6e9746d68..a30ee28e0 100644
--- a/spec/helpers/markdownify_helper_spec.rb
+++ b/spec/helpers/markdownify_helper_spec.rb
@@ -35,6 +35,15 @@ describe MarkdownifyHelper do
markdownify(proto+"://"+url).should == ""+url+""
end
+ it "doesn't double parse video links" do
+ message = "http://www.vimeo.com/17449557
+ http://www.youtube.com/watch?v=0x__dDWdf23&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1
+ http://youtu.be/x_CzD0GBD-4"
+ res = markdownify(message)
+ res.should =~ /href.+href.+href/
+ res.should_not =~ /href.+href.+href.+href/
+ end
+
describe "video links" do
it "recognizes vimeo links" do
video_id = "17449557"
@@ -62,6 +71,15 @@ describe MarkdownifyHelper do
res.should =~ /data-video-id="#{video_id}"/
end
+ it "recognizes youtu.be links" do
+ video_id = "x_CzD0GBD-4"
+ url = "http://youtu.be/#{video_id}"
+ res = markdownify(url)
+ res.should =~ /Youtube:/
+ res.should =~ /data-host="youtube.com"/
+ res.should =~ /data-video-id="#{video_id}"/
+ end
+
it "recognizes youtube links with hyphens" do
video_id = "ABYnqp-bxvg"
url = "http://www.youtube.com/watch?v=" + video_id + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"