Upgrade url_for to search for resources relative to their destination paths as well as their source paths. This would fix #818.
This commit is contained in:
parent
8f4057736a
commit
22dace72df
|
@ -27,12 +27,12 @@ Feature: Directory Index
|
|||
And the file "regular/index.html" should contain "Regular"
|
||||
And the file "evil spaces/index.html" should contain "Spaces"
|
||||
|
||||
|
||||
|
||||
Scenario: Preview normal file
|
||||
Given the Server is running at "indexable-app"
|
||||
When I go to "/needs_index/"
|
||||
Then I should see "Indexable"
|
||||
|
||||
|
||||
Scenario: Preview normal file with spaces in filename
|
||||
Given the Server is running at "indexable-app"
|
||||
When I go to "/evil%20spaces/"
|
||||
|
@ -42,7 +42,7 @@ Feature: Directory Index
|
|||
Given the Server is running at "indexable-app"
|
||||
When I go to "/a_folder/needs_index/"
|
||||
Then I should see "Indexable"
|
||||
|
||||
|
||||
Scenario: Preview ignored file
|
||||
Given the Server is running at "indexable-app"
|
||||
When I go to "/leave_me_alone/"
|
||||
|
@ -69,14 +69,13 @@ Feature: Directory Index
|
|||
And the Server is running at "indexable-app"
|
||||
When I go to "/link_to/"
|
||||
Then I should see 'link_to: <a href="/needs_index/">Needs Index</a>'
|
||||
Then I should see 'explicit_link_to: <a href="/needs_index/index.html">Explicit</a>'
|
||||
Then I should see 'explicit_link_to: <a href="/needs_index/">Explicit</a>'
|
||||
Then I should see 'unknown_link_to: <a href="/unknown.html">Unknown</a>'
|
||||
Then I should see 'relative_link_to: <a href="/needs_index/">Relative</a>'
|
||||
Then I should see 'link_to_with_spaces: <a href="/evil%20spaces/">Spaces</a>'
|
||||
When I go to "/link_to/sub/"
|
||||
Then I should see 'link_to: <a href="/needs_index/">Needs Index</a>'
|
||||
Then I should see 'explicit_link_to: <a href="/needs_index/index.html">Explicit</a>'
|
||||
Then I should see 'explicit_link_to: <a href="/needs_index/">Explicit</a>'
|
||||
Then I should see 'unknown_link_to: <a href="/unknown.html">Unknown</a>'
|
||||
Then I should see 'relative_link_to: <a href="/needs_index/">Relative</a>'
|
||||
Then I should see 'link_to_with_spaces: <a href="/evil%20spaces/">Spaces</a>'
|
||||
|
||||
|
|
|
@ -247,7 +247,16 @@ module Middleman
|
|||
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
|
||||
if resource
|
||||
resource_url = resource.url
|
||||
else
|
||||
# Try to find a resource relative to destination paths
|
||||
url_path = Pathname(uri.path)
|
||||
current_source_dir = Pathname('/' + this_resource.destination_path).dirname
|
||||
url_path = current_source_dir.join(url_path) if url_path.relative?
|
||||
resource = app.sitemap.find_resource_by_destination_path(url_path.to_s)
|
||||
resource_url = resource.url if resource
|
||||
end
|
||||
elsif options[:find_resource] && uri.path
|
||||
resource = app.sitemap.find_resource_by_path(uri.path)
|
||||
resource_url = resource.url if resource
|
||||
|
|
Loading…
Reference in a new issue