Skip to content

Commit 97aeb6c

Browse files
committed
1 parent 92eb695 commit 97aeb6c

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Http/Controllers/Api/ApiFormAutocompleteController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private function checkEndpoint(string $requestEndpoint, string $fieldEndpoint):
129129
{
130130
collect(Route::getRoutes()->getRoutes())
131131
->map(fn ($route) => url($route->uri))
132-
->filter(fn ($routeUrl) => $routeUrl == $requestEndpoint)
132+
->filter(fn ($routeUrl) => $routeUrl == str($requestEndpoint)->before('?'))
133133
->count() > 0 ?: throw new SharpInvalidConfigException('The endpoint is not a valid internal route.');
134134

135135
preg_match(

tests/Http/Api/ApiFormAutocompleteControllerTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,34 @@ public function buildFormFields(FieldsContainer $formFields): void
365365
]);
366366
})->throws(\Code16\Sharp\Exceptions\SharpInvalidConfigException::class);
367367

368+
it('allows internal remote endpoint with a querystring', function () {
369+
$this->withoutExceptionHandling();
370+
371+
fakeFormFor('person', new class() extends PersonForm
372+
{
373+
public function buildFormFields(FieldsContainer $formFields): void
374+
{
375+
$formFields->addField(
376+
SharpFormAutocompleteRemoteField::make('autocomplete_field')
377+
->setRemoteMethodPOST()
378+
->setRemoteEndpoint('/my/endpoint')
379+
);
380+
}
381+
});
382+
383+
Route::post('/my/endpoint', fn () => []);
384+
385+
$this
386+
->postJson(route('code16.sharp.api.form.autocomplete.index', [
387+
'entityKey' => 'person',
388+
'autocompleteFieldKey' => 'autocomplete_field',
389+
]), [
390+
'endpoint' => url('my/endpoint?param1=one'),
391+
'search' => 'my search',
392+
])
393+
->assertOk();
394+
});
395+
368396
it('allows to call an functional endpoint for a remote autocomplete field in an embed of an Editor field', function () {
369397
fakeFormFor('person', new class() extends PersonForm
370398
{

0 commit comments

Comments
 (0)