diff --git a/src/Http/Controllers/Api/ApiFormAutocompleteController.php b/src/Http/Controllers/Api/ApiFormAutocompleteController.php index 120f65063..c17d20ae0 100644 --- a/src/Http/Controllers/Api/ApiFormAutocompleteController.php +++ b/src/Http/Controllers/Api/ApiFormAutocompleteController.php @@ -129,7 +129,7 @@ private function checkEndpoint(string $requestEndpoint, string $fieldEndpoint): { collect(Route::getRoutes()->getRoutes()) ->map(fn ($route) => url($route->uri)) - ->filter(fn ($routeUrl) => $routeUrl == $requestEndpoint) + ->filter(fn ($routeUrl) => $routeUrl == str($requestEndpoint)->before('?')) ->count() > 0 ?: throw new SharpInvalidConfigException('The endpoint is not a valid internal route.'); preg_match( diff --git a/tests/Http/Api/ApiFormAutocompleteControllerTest.php b/tests/Http/Api/ApiFormAutocompleteControllerTest.php index 299f1a1c0..b55c06057 100644 --- a/tests/Http/Api/ApiFormAutocompleteControllerTest.php +++ b/tests/Http/Api/ApiFormAutocompleteControllerTest.php @@ -365,6 +365,34 @@ public function buildFormFields(FieldsContainer $formFields): void ]); })->throws(\Code16\Sharp\Exceptions\SharpInvalidConfigException::class); +it('allows internal remote endpoint with a querystring', function () { + $this->withoutExceptionHandling(); + + fakeFormFor('person', new class() extends PersonForm + { + public function buildFormFields(FieldsContainer $formFields): void + { + $formFields->addField( + SharpFormAutocompleteRemoteField::make('autocomplete_field') + ->setRemoteMethodPOST() + ->setRemoteEndpoint('/my/endpoint') + ); + } + }); + + Route::post('/my/endpoint', fn () => []); + + $this + ->postJson(route('code16.sharp.api.form.autocomplete.index', [ + 'entityKey' => 'person', + 'autocompleteFieldKey' => 'autocomplete_field', + ]), [ + 'endpoint' => url('my/endpoint?param1=one'), + 'search' => 'my search', + ]) + ->assertOk(); +}); + it('allows to call an functional endpoint for a remote autocomplete field in an embed of an Editor field', function () { fakeFormFor('person', new class() extends PersonForm {