From 1ca5be7b1927c4b2fa061ac3955bb121bb186fb8 Mon Sep 17 00:00:00 2001 From: Ulrich Gabor Date: Tue, 5 Jan 2016 15:10:49 +0100 Subject: [PATCH 1/2] Tests for issue #1702 --- .../features/encoding_option.feature | 23 +++++++++++++++++++ .../fixtures/i-8859-1-app/config.rb | 1 + .../i-8859-1-app/source/index.html.erb | 1 + .../step_definitions/server_steps.rb | 4 ++++ 4 files changed, 29 insertions(+) create mode 100644 middleman-core/features/encoding_option.feature create mode 100644 middleman-core/fixtures/i-8859-1-app/config.rb create mode 100644 middleman-core/fixtures/i-8859-1-app/source/index.html.erb diff --git a/middleman-core/features/encoding_option.feature b/middleman-core/features/encoding_option.feature new file mode 100644 index 00000000..b2aeed6b --- /dev/null +++ b/middleman-core/features/encoding_option.feature @@ -0,0 +1,23 @@ +# encoding: iso-8859-1 +Feature: encoding option + + Scenario: No encoding set + Given a fixture app "clean-app" + Given the Server is running at "clean-app" + + When I go to "/index.html" + Then the "Content-Type" header should contain "text/html" + Then the "Content-Type" header should contain "charset=utf-8" + + Scenario: Custom encoding set + Given a fixture app "i-8859-1-app" + And a file named "config.rb" with: + """ + set :encoding, "ISO-8859-1" + """ + Given the Server is running at "i-8859-1-app" + + When I go to "/index.html" + Then the "Content-Type" header should contain "text/html" + Then the "Content-Type" header should contain "charset=iso-8859-1" + Then I should see "äöü" diff --git a/middleman-core/fixtures/i-8859-1-app/config.rb b/middleman-core/fixtures/i-8859-1-app/config.rb new file mode 100644 index 00000000..3252ee63 --- /dev/null +++ b/middleman-core/fixtures/i-8859-1-app/config.rb @@ -0,0 +1 @@ +set :encoding, "ISO-8859-1" diff --git a/middleman-core/fixtures/i-8859-1-app/source/index.html.erb b/middleman-core/fixtures/i-8859-1-app/source/index.html.erb new file mode 100644 index 00000000..3c015801 --- /dev/null +++ b/middleman-core/fixtures/i-8859-1-app/source/index.html.erb @@ -0,0 +1 @@ +äöü diff --git a/middleman-core/lib/middleman-core/step_definitions/server_steps.rb b/middleman-core/lib/middleman-core/step_definitions/server_steps.rb index 9ff79474..7defbbc0 100644 --- a/middleman-core/lib/middleman-core/step_definitions/server_steps.rb +++ b/middleman-core/lib/middleman-core/step_definitions/server_steps.rb @@ -75,6 +75,10 @@ Then /^the content type should be "([^\"]*)"$/ do |expected| expect(page.response_headers['Content-Type']).to start_with expected end +Then /^the "([^\"]*)" header should contain "([^\"]*)"$/ do |header, expected| + expect(page.response_headers[header]).to include expected +end + Then /^I should see "([^\"]*)"$/ do |expected| expect(page.body).to include expected end From 298b3909ed970cc7c5e6c70af45d073e16c55039 Mon Sep 17 00:00:00 2001 From: Ulrich Gabor Date: Tue, 5 Jan 2016 15:11:14 +0100 Subject: [PATCH 2/2] First fix to actually use the encoding option again --- middleman-core/lib/middleman-core/application.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index ff2d4e4f..5818548b 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -253,11 +253,6 @@ module Middleman # Initialize the Sitemap @sitemap = ::Middleman::Sitemap::Store.new(self) - if Object.const_defined?(:Encoding) - Encoding.default_internal = config[:encoding] - Encoding.default_external = config[:encoding] - end - ::Middleman::Extension.clear_after_extension_callbacks after_configuration_eval(&method(:prune_tilt_templates)) @@ -276,6 +271,10 @@ module Middleman # Eval config. evaluate_configuration! + if Object.const_defined?(:Encoding) + Encoding.default_external = config[:encoding] + end + # Run any `configure` blocks for the current environment. execute_callbacks([:configure, config[:environment]])