Don't lookup resource for path if the path is absolute. Fixes #1195

This commit is contained in:
Thomas Reynolds 2015-03-03 13:09:46 -08:00
parent a71589becd
commit 7f2048b865
2 changed files with 20 additions and 2 deletions

View file

@ -5,6 +5,24 @@ Feature: link_to helper
When I go to "/link_to_erb.html"
Then I should see "erb <s>with html tags</s>"
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 '<a href="http://google.com/test.html">test</a>'
Scenario: link_to works with blocks (slim)
Given the Server is running at "link-to-app"
When I go to "/link_to_slim.html"

View file

@ -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