From a94cd7fd6d749cf37851f9db2eecc9bf99e00568 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Sat, 12 Nov 2016 14:56:39 +0900 Subject: [PATCH] Allow an empty or null base URI --- app/concerns/liquid_interpolatable.rb | 7 ++++--- spec/concerns/liquid_interpolatable_spec.rb | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/concerns/liquid_interpolatable.rb b/app/concerns/liquid_interpolatable.rb index 83d93dec..4bc0d091 100644 --- a/app/concerns/liquid_interpolatable.rb +++ b/app/concerns/liquid_interpolatable.rb @@ -129,10 +129,11 @@ module LiquidInterpolatable # userinfo, host, port, registry, path, opaque, query, and # fragment. def to_uri(uri, base_uri = nil) - if base_uri - Utils.normalize_uri(base_uri) + Utils.normalize_uri(uri.to_s) - else + case base_uri + when nil, '' Utils.normalize_uri(uri.to_s) + else + Utils.normalize_uri(base_uri) + Utils.normalize_uri(uri.to_s) end rescue URI::Error nil diff --git a/spec/concerns/liquid_interpolatable_spec.rb b/spec/concerns/liquid_interpolatable_spec.rb index 6c7c9a71..b58b9996 100644 --- a/spec/concerns/liquid_interpolatable_spec.rb +++ b/spec/concerns/liquid_interpolatable_spec.rb @@ -119,6 +119,15 @@ describe LiquidInterpolatable::Filters do @agent.interpolation_context['s'] = 'foo/index.html' expect(@agent.interpolated['foo']).to eq('/dir/foo/index.html') end + + it 'should normalize a URI value if an empty base URI is given' do + @agent.options['foo'] = '{{ u | to_uri: b }}' + @agent.interpolation_context['u'] = "\u{3042}" + @agent.interpolation_context['b'] = "" + expect(@agent.interpolated['foo']).to eq('%E3%81%82') + @agent.interpolation_context['b'] = nil + expect(@agent.interpolated['foo']).to eq('%E3%81%82') + end end describe 'uri_expand' do