From 76f591788e8c8922973cbf6ca061691f5e686b40 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Sun, 13 Dec 2015 13:06:05 -0800 Subject: [PATCH] Change inline URL matcher to only match strings, not newlines. Fixes #1689 --- middleman-core/features/relative_assets.feature | 5 +++++ middleman-core/fixtures/relative-assets-app/config.rb | 6 +++++- .../source/fonts/roboto/roboto-regular-webfont.eot | 0 .../source/fonts/roboto/roboto-regular-webfont.svg | 0 .../source/fonts/roboto/roboto-regular-webfont.ttf | 0 .../source/fonts/roboto/roboto-regular-webfont.woff | 0 .../relative-assets-app/source/stylesheets/fonts.css | 10 ++++++++++ .../lib/middleman-core/extensions/relative_assets.rb | 2 +- middleman-core/lib/middleman-core/util.rb | 4 +++- 9 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 middleman-core/fixtures/relative-assets-app/source/fonts/roboto/roboto-regular-webfont.eot create mode 100644 middleman-core/fixtures/relative-assets-app/source/fonts/roboto/roboto-regular-webfont.svg create mode 100644 middleman-core/fixtures/relative-assets-app/source/fonts/roboto/roboto-regular-webfont.ttf create mode 100644 middleman-core/fixtures/relative-assets-app/source/fonts/roboto/roboto-regular-webfont.woff create mode 100644 middleman-core/fixtures/relative-assets-app/source/stylesheets/fonts.css diff --git a/middleman-core/features/relative_assets.feature b/middleman-core/features/relative_assets.feature index e78f7665..0f782761 100644 --- a/middleman-core/features/relative_assets.feature +++ b/middleman-core/features/relative_assets.feature @@ -36,6 +36,11 @@ Feature: Relative Assets Then I should see 'url("../images/blank.gif' When I go to "/javascripts/application.js" Then I should not see "../" + When I go to "/stylesheets/fonts.css" + Then I should see 'url(../fonts/roboto/roboto-regular-webfont.eot' + And I should see 'url(../fonts/roboto/roboto-regular-webfont.woff' + And I should see 'url(../fonts/roboto/roboto-regular-webfont.ttf' + And I should see 'url(../fonts/roboto/roboto-regular-webfont.svg' Scenario: Building css with the feature enabled Given a fixture app "relative-assets-app" diff --git a/middleman-core/fixtures/relative-assets-app/config.rb b/middleman-core/fixtures/relative-assets-app/config.rb index 8ef98b2f..86b77274 100644 --- a/middleman-core/fixtures/relative-assets-app/config.rb +++ b/middleman-core/fixtures/relative-assets-app/config.rb @@ -1 +1,5 @@ -# activate :relative_assets +set :fonts_dir, 'fonts' + +configure :build do + activate :relative_assets +end diff --git a/middleman-core/fixtures/relative-assets-app/source/fonts/roboto/roboto-regular-webfont.eot b/middleman-core/fixtures/relative-assets-app/source/fonts/roboto/roboto-regular-webfont.eot new file mode 100644 index 00000000..e69de29b diff --git a/middleman-core/fixtures/relative-assets-app/source/fonts/roboto/roboto-regular-webfont.svg b/middleman-core/fixtures/relative-assets-app/source/fonts/roboto/roboto-regular-webfont.svg new file mode 100644 index 00000000..e69de29b diff --git a/middleman-core/fixtures/relative-assets-app/source/fonts/roboto/roboto-regular-webfont.ttf b/middleman-core/fixtures/relative-assets-app/source/fonts/roboto/roboto-regular-webfont.ttf new file mode 100644 index 00000000..e69de29b diff --git a/middleman-core/fixtures/relative-assets-app/source/fonts/roboto/roboto-regular-webfont.woff b/middleman-core/fixtures/relative-assets-app/source/fonts/roboto/roboto-regular-webfont.woff new file mode 100644 index 00000000..e69de29b diff --git a/middleman-core/fixtures/relative-assets-app/source/stylesheets/fonts.css b/middleman-core/fixtures/relative-assets-app/source/stylesheets/fonts.css new file mode 100644 index 00000000..ef6c7dfe --- /dev/null +++ b/middleman-core/fixtures/relative-assets-app/source/stylesheets/fonts.css @@ -0,0 +1,10 @@ +@font-face { + font-family: 'Roboto'; + src: url(/fonts/roboto/roboto-regular-webfont.eot); + src: url(/fonts/roboto/roboto-regular-webfont.eot?#iefix) format('embedded-opentype'), + url(/fonts/roboto/roboto-regular-webfont.woff) format('woff'), + url(/fonts/roboto/roboto-regular-webfont.ttf) format('truetype'), + url(/fonts/roboto/roboto-regular-webfont.svg#robotoregular) format('svg'); + font-weight: normal; + font-style: normal; +} diff --git a/middleman-core/lib/middleman-core/extensions/relative_assets.rb b/middleman-core/lib/middleman-core/extensions/relative_assets.rb index 0522d845..4de2f2d5 100644 --- a/middleman-core/lib/middleman-core/extensions/relative_assets.rb +++ b/middleman-core/lib/middleman-core/extensions/relative_assets.rb @@ -2,7 +2,7 @@ require 'addressable/uri' # Relative Assets extension class Middleman::Extensions::RelativeAssets < ::Middleman::Extension - option :exts, %w(.css .png .jpg .jpeg .webp .svg .svgz .js .gif .ttf .otf .woff .woff2), 'List of extensions that get cache busters strings appended to them.' + option :exts, %w(.css .png .jpg .jpeg .webp .svg .svgz .js .gif .ttf .otf .woff .woff2 .eot), 'List of extensions that get cache busters strings appended to them.' option :sources, %w(.htm .html .css), 'List of extensions that are searched for relative assets.' option :ignore, [], 'Regexes of filenames to skip adding query strings to' diff --git a/middleman-core/lib/middleman-core/util.rb b/middleman-core/lib/middleman-core/util.rb index 18e13435..4d700e0e 100644 --- a/middleman-core/lib/middleman-core/util.rb +++ b/middleman-core/lib/middleman-core/util.rb @@ -332,7 +332,9 @@ module Middleman Contract String, String, ArrayOf[String], Proc => String def rewrite_paths(body, _path, exts, &_block) - body.dup.gsub(/([=\'\"\(,]\s*)([^\s\'\"\)>]+(#{Regexp.union(exts)}))/) do |match| + matcher = /([=\'\"\(,] *)([^\s\'\"\)>]+(#{Regexp.union(exts)}))/ + + body.dup.gsub(matcher) do |match| opening_character = $1 asset_path = $2