From 7f2048b8655216b22ca0f39af539a22445554f32 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Tue, 3 Mar 2015 13:09:46 -0800 Subject: [PATCH] Don't lookup resource for path if the path is absolute. Fixes #1195 --- .../features/helpers_link_to.feature | 18 ++++++++++++++++++ middleman-core/lib/middleman-core/util.rb | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/middleman-core/features/helpers_link_to.feature b/middleman-core/features/helpers_link_to.feature index 162c1e8a..d6caf6cf 100644 --- a/middleman-core/features/helpers_link_to.feature +++ b/middleman-core/features/helpers_link_to.feature @@ -5,6 +5,24 @@ Feature: link_to helper When I go to "/link_to_erb.html" Then I should see "erb with html tags" + Scenario: link_to works with absolute URLs (where the relative part matches a local path) + Given a fixture app "link-to-app" + And a file named "config.rb" with: + """ + set :relative_links, true + """ + And a file named "source/test.html.erb" with: + """ + Hello + """ + And a file named "source/link_to_absolute.html.erb" with: + """ + <%= link_to "test", "http://google.com/test.html" %> + """ + And the Server is running at "link-to-app" + When I go to "/link_to_absolute.html" + Then I should see 'test' + Scenario: link_to works with blocks (slim) Given the Server is running at "link-to-app" When I go to "/link_to_slim.html" diff --git a/middleman-core/lib/middleman-core/util.rb b/middleman-core/lib/middleman-core/util.rb index 7a4e2d35..1c4b74ed 100644 --- a/middleman-core/lib/middleman-core/util.rb +++ b/middleman-core/lib/middleman-core/util.rb @@ -169,14 +169,14 @@ module Middleman if path_or_resource.is_a?(::Middleman::Sitemap::Resource) resource = path_or_resource resource_url = url - elsif this_resource && uri.path + elsif this_resource && uri.path && !uri.host # Handle relative urls url_path = Pathname(uri.path) current_source_dir = Pathname('/' + this_resource.path).dirname url_path = current_source_dir.join(url_path) if url_path.relative? resource = app.sitemap.find_resource_by_path(url_path.to_s) resource_url = resource.url if resource - elsif options[:find_resource] && uri.path + elsif options[:find_resource] && uri.path && !uri.host resource = app.sitemap.find_resource_by_path(uri.path) resource_url = resource.url if resource end