Skip to content

http: optional HttpQuery with a dotted name gives 500 when it is missing #778

Open

Description

@lionelhorn

An optional query parameter whose name has a dot (filter.name, read from ?filter[name]=) makes the route answer 500 when the request has no filter. The server logs TypeError: Cannot read properties of undefined (reading 'name').

import { App } from '@deepkit/app';
import { http, HttpKernel, HttpModule, HttpQuery, HttpRequest } from '@deepkit/http';

// reads ?filter[name]=...
type FilterName = HttpQuery<string, { name: 'filter.name' }>;

class ProductController {
    @http.GET('/products')
    list(name?: FilterName) {
        return name ?? 'all';
    }
}

const app = new App({ controllers: [ProductController], imports: [new HttpModule()] });
const kernel = app.get(HttpKernel);

const filtered = await kernel.request(HttpRequest.GET('/products?filter[name]=shoes'));
console.log(filtered.statusCode, filtered.bodyString);
// 200 "shoes"
const unfiltered = await kernel.request(HttpRequest.GET('/products'));
console.log(unfiltered.statusCode, unfiltered.bodyString);
// actual: 500 Internal error, should be: 200 "all"

Master 0bb9fba, Node 26.13.0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions