From 561ddc95587f4dc7626a7dafeb85e13a96e812b8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Feb 2026 17:07:23 +0000 Subject: [PATCH 1/2] Initial plan From 1aa052f7429fedd8e9a2ea31dacbce6466bdbf72 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Feb 2026 17:13:45 +0000 Subject: [PATCH 2/2] URL-encode branch names in DevPullCommand to handle slashes Co-authored-by: sak0a <24781653+sak0a@users.noreply.github.com> --- src/Console/Commands/DevPullCommand.php | 3 +- tests/Unit/Console/DevPullCommandTest.php | 195 ++++++++++++++++++++++ 2 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/Console/DevPullCommandTest.php diff --git a/src/Console/Commands/DevPullCommand.php b/src/Console/Commands/DevPullCommand.php index 370585d8..887a2ebe 100644 --- a/src/Console/Commands/DevPullCommand.php +++ b/src/Console/Commands/DevPullCommand.php @@ -192,7 +192,8 @@ public function handle(): int private function fetchCommitInfo(Client $client, string $repo, string $ref): array { - $url = self::GITHUB_API_BASE . "/repos/{$repo}/commits/{$ref}"; + $encodedRef = rawurlencode($ref); + $url = self::GITHUB_API_BASE . "/repos/{$repo}/commits/{$encodedRef}"; try { $response = $client->get($url); diff --git a/tests/Unit/Console/DevPullCommandTest.php b/tests/Unit/Console/DevPullCommandTest.php new file mode 100644 index 00000000..9696b2b6 --- /dev/null +++ b/tests/Unit/Console/DevPullCommandTest.php @@ -0,0 +1,195 @@ +set('database.default', 'testing'); + $app['config']->set('database.connections.testing', [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', + ]); + $app['config']->set('notur.repository', 'sak0a/notur'); + } + + public function test_url_encodes_branch_names_with_slashes(): void + { + // Create a mock handler to capture HTTP requests + $container = []; + $history = Middleware::history($container); + + $mock = new MockHandler([ + new Response(200, [], json_encode([ + 'sha' => 'abc123def456', + 'commit' => [ + 'message' => 'Test commit', + 'author' => [ + 'name' => 'Test Author', + 'date' => '2026-02-07T12:00:00Z', + ], + ], + ])), + ]); + + $handlerStack = HandlerStack::create($mock); + $handlerStack->push($history); + + // Test with a branch name containing slashes + $client = new Client(['handler' => $handlerStack]); + + $command = new DevPullCommand(); + $reflection = new \ReflectionClass($command); + $method = $reflection->getMethod('fetchCommitInfo'); + $method->setAccessible(true); + + $method->invoke($command, $client, 'sak0a/notur', 'feature/my-branch'); + + // Verify the URL was properly encoded + $this->assertCount(1, $container); + $request = $container[0]['request']; + $uri = (string) $request->getUri(); + + // The branch name should be URL-encoded: feature/my-branch -> feature%2Fmy-branch + $this->assertStringContainsString('/commits/feature%2Fmy-branch', $uri); + $this->assertStringNotContainsString('/commits/feature/my-branch', $uri); + } + + public function test_url_encodes_branch_names_with_special_characters(): void + { + // Create a mock handler + $container = []; + $history = Middleware::history($container); + + $mock = new MockHandler([ + new Response(200, [], json_encode([ + 'sha' => 'xyz789abc', + 'commit' => [ + 'message' => 'Another test', + 'author' => [ + 'name' => 'Test Author', + 'date' => '2026-02-07T12:00:00Z', + ], + ], + ])), + ]); + + $handlerStack = HandlerStack::create($mock); + $handlerStack->push($history); + + $client = new Client(['handler' => $handlerStack]); + + $command = new DevPullCommand(); + $reflection = new \ReflectionClass($command); + $method = $reflection->getMethod('fetchCommitInfo'); + $method->setAccessible(true); + + // Test with a branch name containing spaces and special characters + $method->invoke($command, $client, 'sak0a/notur', 'feature/my branch-v2'); + + $this->assertCount(1, $container); + $request = $container[0]['request']; + $uri = (string) $request->getUri(); + + // The branch name should be URL-encoded + $this->assertStringContainsString('/commits/feature%2Fmy%20branch-v2', $uri); + } + + public function test_handles_simple_branch_names_correctly(): void + { + // Create a mock handler + $container = []; + $history = Middleware::history($container); + + $mock = new MockHandler([ + new Response(200, [], json_encode([ + 'sha' => '123abc456', + 'commit' => [ + 'message' => 'Simple test', + 'author' => [ + 'name' => 'Test Author', + 'date' => '2026-02-07T12:00:00Z', + ], + ], + ])), + ]); + + $handlerStack = HandlerStack::create($mock); + $handlerStack->push($history); + + $client = new Client(['handler' => $handlerStack]); + + $command = new DevPullCommand(); + $reflection = new \ReflectionClass($command); + $method = $reflection->getMethod('fetchCommitInfo'); + $method->setAccessible(true); + + // Test with a simple branch name without special characters + $method->invoke($command, $client, 'sak0a/notur', 'main'); + + $this->assertCount(1, $container); + $request = $container[0]['request']; + $uri = (string) $request->getUri(); + + // Simple branch names should still work + $this->assertStringContainsString('/commits/main', $uri); + } + + public function test_handles_commit_sha(): void + { + // Create a mock handler + $container = []; + $history = Middleware::history($container); + + $mock = new MockHandler([ + new Response(200, [], json_encode([ + 'sha' => 'abc123def456789', + 'commit' => [ + 'message' => 'SHA test', + 'author' => [ + 'name' => 'Test Author', + 'date' => '2026-02-07T12:00:00Z', + ], + ], + ])), + ]); + + $handlerStack = HandlerStack::create($mock); + $handlerStack->push($history); + + $client = new Client(['handler' => $handlerStack]); + + $command = new DevPullCommand(); + $reflection = new \ReflectionClass($command); + $method = $reflection->getMethod('fetchCommitInfo'); + $method->setAccessible(true); + + // Test with a commit SHA (no special characters) + $method->invoke($command, $client, 'sak0a/notur', 'abc123def456789'); + + $this->assertCount(1, $container); + $request = $container[0]['request']; + $uri = (string) $request->getUri(); + + // Commit SHAs should work as expected + $this->assertStringContainsString('/commits/abc123def456789', $uri); + } +}