diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index a1b1a8b6b..a599438a1 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -216,16 +216,18 @@ module ApplicationHelper
end
def process_youtube(message, youtube_maps)
- regex = /( |^)(https?:\/\/)?www\.youtube\.com\/watch[^ ]*v=([A-Za-z0-9_\-]+)(&[^ ]*|)/
+ regex = /( |^)(https?:\/\/)?www\.youtube\.com\/watch[^ ]*v=([A-Za-z0-9_\-]+)(&[^ ]*)?(#[^ ]+)?/
processed_message = message.gsub(regex) do |matched_string|
match_data = matched_string.match(regex)
video_id = match_data[3]
+ anchor = match_data[5]
+ anchor ||= ''
if youtube_maps && youtube_maps[video_id]
title = h(CGI::unescape(youtube_maps[video_id]))
else
title = I18n.t 'application.helper.video_title.unknown'
end
- ' Youtube: ' + title + ''
+ ' Youtube: ' + title + ''
end
return processed_message
end
diff --git a/public/javascripts/widgets/embedder.js b/public/javascripts/widgets/embedder.js
index 3519339ba..1f2e4da50 100644
--- a/public/javascripts/widgets/embedder.js
+++ b/public/javascripts/widgets/embedder.js
@@ -65,8 +65,8 @@
var watchVideoOn = Diaspora.widgets.i18n.t("videos.watch");
this.register("youtube.com",
- '' + $.mustache(watchVideoOn, { provider: "YouTube" }) + '
' +
- '');
+ '' + $.mustache(watchVideoOn, { provider: "YouTube" }) + '
' +
+ '');
this.register("vimeo.com",
'' + $.mustache(watchVideoOn, { provider: "Vimeo" }) + '
' +
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 74f1fdc6b..6660ace48 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -101,6 +101,27 @@ describe ApplicationHelper do
res.should =~ /data-video-id="#{video_id}"/
end
+ it "keeps anchors" do
+ anchor = "#t=11m34"
+ video_id = "DHRoHuv3I8E"
+ url = "http://www.youtube.com/watch?v=" + video_id + anchor
+ res = markdownify(url)
+ res.should =~ /Youtube:/
+ res.should =~ /data-host="youtube.com"/
+ res.should =~ /data-video-id="#{video_id}"/
+ res.should =~ /data-anchor="#{anchor}"/
+ end
+
+ it "has an empty data-anchor attribute if there is no anchor" do
+ video_id = "DHRoHuv3I8E"
+ url = "http://www.youtube.com/watch?v=" + video_id
+ res = markdownify(url)
+ res.should =~ /Youtube:/
+ res.should =~ /data-host="youtube.com"/
+ res.should =~ /data-video-id="#{video_id}"/
+ res.should =~ /data-anchor=""/
+ end
+
it "leaves the links in the href of the #a tag" do
video_id = "ABYnqp-bxvg"
start_url ="http://www.youtube.com/watch?v=" + video_id