From 5da6305b1009f740c00d271de0247cab8ebb5231 Mon Sep 17 00:00:00 2001 From: Arzumy MD Date: Wed, 4 May 2011 23:54:25 +0800 Subject: [PATCH] #1019 YoutubeTitles::YOUTUBE_ID_REGEX supports data-anchor --- app/helpers/application_helper.rb | 9 ++++----- lib/youtube_titles.rb | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 76547b8c3..778e43355 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -212,11 +212,10 @@ module ApplicationHelper end def process_youtube(message, youtube_maps) - 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] + processed_message = message.gsub(YoutubeTitles::YOUTUBE_ID_REGEX) do |matched_string| + match_data = matched_string.match(YoutubeTitles::YOUTUBE_ID_REGEX) + video_id = match_data[1] + anchor = match_data[2] anchor ||= '' if youtube_maps && youtube_maps[video_id] title = h(CGI::unescape(youtube_maps[video_id])) diff --git a/lib/youtube_titles.rb b/lib/youtube_titles.rb index 7262da5fe..760cb703b 100644 --- a/lib/youtube_titles.rb +++ b/lib/youtube_titles.rb @@ -20,5 +20,5 @@ module YoutubeTitles end end - YOUTUBE_ID_REGEX = /(?:youtu\.be\/|(?:[a-z]{2,3}\.)?youtube\.com\/watch(?:\?|#!|.+&|.+&)v=)([\w-]{11})/im unless defined? YOUTUBE_ID_REGEX + YOUTUBE_ID_REGEX = /(?:youtu\.be\/|(?:[a-z]{2,3}\.)?youtube\.com\/watch(?:\?|#!|.+&|.+&)v=)([\w-]{11})(?:\S*(#[^ ]+))?/im unless defined? YOUTUBE_ID_REGEX end