Skip to content

Commit 83ac2d4

Browse files
committed
Remove duplicated query string stripping from DefaultIndexer
The SearchProfile already normalizes the URL before passing it to the indexer via useIndexer(), so the DefaultIndexer does not need its own stripQueryString method. Revert url() to simply return $this->url and move all query string tests to the SearchProfile test.
1 parent 6276341 commit 83ac2d4

3 files changed

Lines changed: 22 additions & 42 deletions

File tree

src/Indexers/DefaultIndexer.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,6 @@ public function dateModified(): ?CarbonInterface
176176

177177
public function url(): string
178178
{
179-
return $this->stripQueryString($this->url);
180-
}
181-
182-
protected function stripQueryString(string $url): string
183-
{
184-
$parsed = parse_url($url);
185-
186-
$scheme = isset($parsed['scheme']) ? $parsed['scheme'].'://' : '';
187-
$host = $parsed['host'] ?? '';
188-
$port = isset($parsed['port']) ? ':'.$parsed['port'] : '';
189-
$path = $parsed['path'] ?? '';
190-
$fragment = isset($parsed['fragment']) ? '#'.$parsed['fragment'] : '';
191-
192-
return $scheme.$host.$port.$path.$fragment;
179+
return $this->url;
193180
}
194181
}

tests/Indexers/DefaultIndexTest.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,6 @@
5656
expect($subsectionContent['anchor'])->toBe('subsection'); // Inherits from h3
5757
});
5858

59-
it('strips query strings from the url', function () {
60-
$indexer = new DefaultIndexer(
61-
'https://example.com/post?utm_source=newsletter&utm_medium=email',
62-
CrawlResponse::fake(body: view('test::page'))
63-
);
64-
65-
expect($indexer->url())->toEqual('https://example.com/post');
66-
});
67-
68-
it('preserves fragments when stripping query strings', function () {
69-
$indexer = new DefaultIndexer(
70-
'https://example.com/post?utm_source=newsletter#section',
71-
CrawlResponse::fake(body: view('test::page'))
72-
);
73-
74-
expect($indexer->url())->toEqual('https://example.com/post#section');
75-
});
76-
77-
it('returns url unchanged when there is no query string', function () {
78-
$indexer = new DefaultIndexer(
79-
'https://example.com/post',
80-
CrawlResponse::fake(body: view('test::page'))
81-
);
82-
83-
expect($indexer->url())->toEqual('https://example.com/post');
84-
});
85-
8659
it('handles headings without id attributes', function () {
8760
$indexer = new DefaultIndexer(
8861
'https://example.com',

tests/Profiles/DefaultSearchProfileTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,27 @@
1717

1818
$response = CrawlResponse::fake(status: 200, body: '<html><body>test</body></html>');
1919

20-
$indexer = $profile->useIndexer('https://example.com/post?utm_source=newsletter', $response);
20+
$indexer = $profile->useIndexer('https://example.com/post?utm_source=newsletter&utm_medium=email', $response);
21+
22+
expect($indexer->url())->toEqual('https://example.com/post');
23+
});
24+
25+
it('preserves fragments when normalizing urls', function () {
26+
$profile = new DefaultSearchProfile;
27+
28+
$response = CrawlResponse::fake(status: 200, body: '<html><body>test</body></html>');
29+
30+
$indexer = $profile->useIndexer('https://example.com/post?utm_source=newsletter#section', $response);
31+
32+
expect($indexer->url())->toEqual('https://example.com/post#section');
33+
});
34+
35+
it('leaves urls without query strings unchanged', function () {
36+
$profile = new DefaultSearchProfile;
37+
38+
$response = CrawlResponse::fake(status: 200, body: '<html><body>test</body></html>');
39+
40+
$indexer = $profile->useIndexer('https://example.com/post', $response);
2141

2242
expect($indexer->url())->toEqual('https://example.com/post');
2343
});

0 commit comments

Comments
 (0)