Fix API::tap_from_source_download for relative paths.
				
					
				
			This commit is contained in:
		
							parent
							
								
									fa23636c44
								
							
						
					
					
						commit
						a6a6a74c48
					
				@ -175,6 +175,7 @@ module Homebrew
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    sig { params(path: Pathname).returns(T.nilable(Tap)) }
 | 
					    sig { params(path: Pathname).returns(T.nilable(Tap)) }
 | 
				
			||||||
    def self.tap_from_source_download(path)
 | 
					    def self.tap_from_source_download(path)
 | 
				
			||||||
 | 
					      path = path.expand_path
 | 
				
			||||||
      source_relative_path = path.relative_path_from(Homebrew::API::HOMEBREW_CACHE_API_SOURCE)
 | 
					      source_relative_path = path.relative_path_from(Homebrew::API::HOMEBREW_CACHE_API_SOURCE)
 | 
				
			||||||
      return if source_relative_path.to_s.start_with?("../")
 | 
					      return if source_relative_path.to_s.start_with?("../")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -67,4 +67,31 @@ describe Homebrew::API do
 | 
				
			|||||||
      end.to raise_error(SystemExit)
 | 
					      end.to raise_error(SystemExit)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  describe "::tap_from_source_download" do
 | 
				
			||||||
 | 
					    let(:api_cache_root) { Homebrew::API::HOMEBREW_CACHE_API_SOURCE }
 | 
				
			||||||
 | 
					    let(:cache_path) do
 | 
				
			||||||
 | 
					      api_cache_root/"Homebrew"/"homebrew-core"/"cf5c386c1fa2cb54279d78c0990dd7a0fa4bc327"/"Formula"/"foo.rb"
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    context "when given a path inside the API source cache" do
 | 
				
			||||||
 | 
					      it "returns the corresponding tap" do
 | 
				
			||||||
 | 
					        expect(described_class.tap_from_source_download(cache_path)).to eq CoreTap.instance
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    context "when given a path that is not inside the API source cache" do
 | 
				
			||||||
 | 
					      let(:api_cache_root) { mktmpdir }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      it "returns nil" do
 | 
				
			||||||
 | 
					        expect(described_class.tap_from_source_download(cache_path)).to be_nil
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    context "when given a relative path that is not inside the API source cache" do
 | 
				
			||||||
 | 
					      it "returns nil" do
 | 
				
			||||||
 | 
					        expect(described_class.tap_from_source_download(Pathname("../foo.rb"))).to be_nil
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user