Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Http/Client/LeverClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private function addParameter(string $field, $value): self
private function prepareOptions(array $body): array
{
if (isset($this->options['query'])) {
$this->options['query'] = preg_replace('/%5B[0-9]%5D/', '',
$this->options['query'] = preg_replace('/%5B\d+%5D/', '',
http_build_query($this->options['query'])
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/QueryStringCleanerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static function buildQuery()
return function (RequestInterface $request, array $options) use ($handler) {
$query = $request->getUri()->getQuery();
$request = $request->withUri(
$request->getUri()->withQuery(preg_replace('/%5B[0-9]%5D/', '', $query)),
$request->getUri()->withQuery(preg_replace('/%5B\d+%5D/', '', $query)),
true
);

Expand Down
29 changes: 29 additions & 0 deletions tests/OpportunitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,35 @@ public function retrieve_opportunities_with_posting()
);
}

/** @test */
public function retrieve_opportunities_with_more_than_ten_postings_strips_all_array_indices()
{
// Regression: QueryStringCleanerMiddleware and prepareOptions() previously
// used preg_replace('/%5B[0-9]%5D/', ...) which only stripped single-digit
// indices ([0]-[9]). Calling posting() 11+ times left posting_id[10]+ in
// the URL, producing malformed query strings that Lever rejects.
$this->mockHandler->append(new Response(200, [], '{"data": {}}'));

$ids = [];
$client = $this->lever->opportunities();
for ($i = 0; $i < 12; $i++) {
$id = sprintf('00000000-0000-0000-0000-%012d', $i + 1);
$ids[] = $id;
$client->posting($id);
}
$client->fetch();

$url = (string) $this->container[0]['request']->getUri();

$this->assertStringNotContainsString('%5B', $url, 'URL must not contain array brackets');
$this->assertStringNotContainsString('posting_id[', urldecode($url), 'URL must not contain array indices');
$this->assertEquals(12, substr_count($url, 'posting_id='));

foreach ($ids as $id) {
$this->assertStringContainsString('posting_id='.$id, $url);
}
}

/** @test */
public function check_archived_reason_is_added_correctly_to_body()
{
Expand Down
Loading