From 60e6f471b07e6d0db55d7a735d92d56abe6ff468 Mon Sep 17 00:00:00 2001 From: hirasawayuki Date: Wed, 10 Nov 2021 21:20:48 +0900 Subject: [PATCH] [Fix #10174] Fix inherit_from_remote should follow remote includes path starting with `./` --- ...rom_remote_should_follow_remote_includes_path.md | 1 + lib/rubocop/remote_config.rb | 2 +- spec/rubocop/remote_config_spec.rb | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 changelog/fix_inherit_from_remote_should_follow_remote_includes_path.md diff --git a/changelog/fix_inherit_from_remote_should_follow_remote_includes_path.md b/changelog/fix_inherit_from_remote_should_follow_remote_includes_path.md new file mode 100644 index 00000000000..af068756402 --- /dev/null +++ b/changelog/fix_inherit_from_remote_should_follow_remote_includes_path.md @@ -0,0 +1 @@ +* [#10174](https://github.com/rubocop/rubocop/issues/10174): Fix inherit_from_remote should follow remote includes path starting with `./`. ([@hirasawayuki][]) diff --git a/lib/rubocop/remote_config.rb b/lib/rubocop/remote_config.rb index 055b0e0aca7..c5ee9eba9e8 100644 --- a/lib/rubocop/remote_config.rb +++ b/lib/rubocop/remote_config.rb @@ -33,7 +33,7 @@ def file def inherit_from_remote(file, path) new_uri = @uri.dup - new_uri.path.gsub!(%r{/[^/]*$}, "/#{file}") + new_uri.path.gsub!(%r{/[^/]*$}, "/#{file.delete_prefix('./')}") RemoteConfig.new(new_uri.to_s, File.dirname(path)) end diff --git a/spec/rubocop/remote_config_spec.rb b/spec/rubocop/remote_config_spec.rb index 9c0b529b2ef..acffb39ffb3 100644 --- a/spec/rubocop/remote_config_spec.rb +++ b/spec/rubocop/remote_config_spec.rb @@ -189,4 +189,17 @@ end end end + + describe '.inherit_from_remote' do + context 'when the remote includes file starting with `./`' do + let(:includes_file) { './base.yml' } + + it 'returns remote includes URI' do + remote_config = described_class.new(remote_config_url, base_dir) + includes_config = remote_config.inherit_from_remote(includes_file, remote_config_url) + + expect(includes_config.uri).to eq URI.parse('http://example.com/base.yml') + end + end + end end