Add specific check for TLD-like strings when replacing inline urls. Fixes #1751

This commit is contained in:
Thomas Reynolds 2016-01-14 14:29:45 -08:00
parent be2788b6ca
commit a47b2138f8
3 changed files with 11 additions and 1 deletions

View file

@ -8,6 +8,7 @@ Feature: Alternate between multiple asset hosts
"""
And the Server is running
When I go to "/asset_host.html"
Then I should see "'.google-analytics.com/ga.js'"
Then I should see 'src="https://code.jquery.com/jquery-2.1.3.min.js"'
Then I should see content matching %r{http://assets1.example.com/}
Then I should not see content matching %r{http://assets1.example.com//}

View file

@ -44,3 +44,12 @@
<a href="https://github.com/angular/angular.js">Angular.js</a>
<script>(function(a,b,c,d){})(window,document,'script','//www.example.com/script.js');</script>
<script>
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') +
'.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

View file

@ -349,7 +349,7 @@ module Middleman
begin
uri = ::Addressable::URI.parse(asset_path)
if uri.relative? && uri.host.nil? && (result = yield asset_path)
if uri.relative? && uri.host.nil? && !asset_path.match(/^[^\/].*[a-z]+\.[a-z]+\/.*/) && (result = yield(asset_path))
"#{opening_character}#{result}"
else
match