From 13bc107b3fe097301981b19248d804072efab69e Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Wed, 26 Apr 2017 12:48:08 -0400 Subject: [PATCH] guard against invalid or missing URLs --- lib/jekyll-seo-tag/drop.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/jekyll-seo-tag/drop.rb b/lib/jekyll-seo-tag/drop.rb index 03702dd..a0c426a 100644 --- a/lib/jekyll-seo-tag/drop.rb +++ b/lib/jekyll-seo-tag/drop.rb @@ -162,6 +162,7 @@ module Jekyll image = { "path" => image } if image.is_a?(String) image["path"] ||= image["facebook"] || image["twitter"] + return @image = nil unless image["path"] unless absolute_url? image["path"] image["path"] = filters.absolute_url image["path"] @@ -177,7 +178,9 @@ module Jekyll end def canonical_url - @canonical_url ||= filters.absolute_url(page["url"]).gsub(%r!/index\.html$!, "/") + @canonical_url ||= begin + filters.absolute_url(page["url"]).to_s.gsub(%r!/index\.html$!, "/") + end end private @@ -205,7 +208,10 @@ module Jekyll end def absolute_url?(string) + return unless string Addressable::URI.parse(string).absolute? + rescue Addressable::URI::InvalidURIError + nil end def format_string(string)