From 6c90f01ae74e30d55449095c9ee62ddc38d8d106 Mon Sep 17 00:00:00 2001 From: Jeena Date: Fri, 21 Aug 2015 21:17:54 +0200 Subject: [PATCH] Resolve relative URLs (bugfix) When the tag is used, the @base wasn't handed down all the way to URLs and photos, this patch fixes this problem. In addition to that it also makes it possible to handle u-url on tags. --- lib/microformats2/format.rb | 4 ++-- lib/microformats2/implied_property/photo.rb | 4 ++++ lib/microformats2/property/foundation.rb | 2 +- lib/microformats2/property/url.rb | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/microformats2/format.rb b/lib/microformats2/format.rb index 74ba975..7d09deb 100644 --- a/lib/microformats2/format.rb +++ b/lib/microformats2/format.rb @@ -40,9 +40,9 @@ module Microformats2 def parse_implied_properties ip = [] - ip << ImpliedProperty::Name.new(@element).parse unless property_present?(:name) + ip << ImpliedProperty::Name.new(@element, @base).parse unless property_present?(:name) ip << ImpliedProperty::Url.new(@element, @base).parse unless property_present?(:url) - ip << ImpliedProperty::Photo.new(@element).parse unless property_present?(:photo) + ip << ImpliedProperty::Photo.new(@element, @base).parse unless property_present?(:photo) ip.compact.each do |property| save_property_name(property.method_name) define_method(property.method_name) diff --git a/lib/microformats2/implied_property/photo.rb b/lib/microformats2/implied_property/photo.rb index 2dc2676..41e4d3f 100644 --- a/lib/microformats2/implied_property/photo.rb +++ b/lib/microformats2/implied_property/photo.rb @@ -6,6 +6,10 @@ module Microformats2 "photo" end + def to_s + @to_s = Microformats2::AbsoluteUri.new(@base, super.to_s).absolutize + end + protected def name_map diff --git a/lib/microformats2/property/foundation.rb b/lib/microformats2/property/foundation.rb index 8851f8e..3ba5bb4 100644 --- a/lib/microformats2/property/foundation.rb +++ b/lib/microformats2/property/foundation.rb @@ -25,7 +25,7 @@ module Microformats2 end def formats - @formats ||= format_classes.length >=1 ? FormatParser.parse(@element) : [] + @formats ||= format_classes.length >=1 ? FormatParser.parse(@element, @base) : [] end def to_hash diff --git a/lib/microformats2/property/url.rb b/lib/microformats2/property/url.rb index c86c6b6..c213ebf 100644 --- a/lib/microformats2/property/url.rb +++ b/lib/microformats2/property/url.rb @@ -15,7 +15,8 @@ module Microformats2 "img" => "src", "object" => "data", "abbr" => "title", - "data" => "value" } + "data" => "value", + "input" => "value" } end end end