From dcefb842dfb3e31d27e52ea9490b7fa0d5a19ee8 Mon Sep 17 00:00:00 2001 From: Kevin Xiwei Zheng Date: Wed, 21 Aug 2013 11:21:11 -0400 Subject: [PATCH] More accurately determine linkable sources Use the "\A" metacharacter for the beginning of a string, instead of "^" for the beginning of any line within that string, and check for "://" as well. Fixes #1947. --- app/helpers/posts_helper.rb | 2 +- app/views/posts/index.atom.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index d1e27edec..11fc0f60d 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -26,7 +26,7 @@ module PostsHelper text = "pixiv/#{$1}" source_link = link_to(text, post.normalized_source) source_search = "source:#{text}/" - elsif post.source =~ /^http/ + elsif post.source =~ %r{\Ahttps?://} text = truncate(post.normalized_source.sub(/^https?:\/\/(?:www\.)?/, "")) source_link = link_to(truncate(text, :length => 20), post.normalized_source) source_search = "source:#{post.source.sub(/[^\/]*$/, "")}" diff --git a/app/views/posts/index.atom.erb b/app/views/posts/index.atom.erb index 598bf1c9f..a0159ba17 100644 --- a/app/views/posts/index.atom.erb +++ b/app/views/posts/index.atom.erb @@ -14,7 +14,7 @@ <%= post.presenter.humanized_essential_tag_string %> - <% if post.source =~ /^http/ %> + <% if post.source =~ %r{\Ahttps?://} %> <% end %> http://<%= Danbooru.config.hostname %>/posts/<%= post.id %>