Skip to content

ValidateHttpRequestWithPathItem panics for path with double slash #274

@oabdoun

Description

@oabdoun

The library panics when validating a request containing a "double slash" to an endpoint with a path parameter.

Given the endpoint spec:

  /test/path/{param}:
    summary: OpenApi Test
    get:
      operationId: PathParamTest
      summary: test
      tags:
        - test
      parameters:
        - in: path
          name: param
          required: true
          schema:
            type: string
      responses:
        "200":
          description: test

When requesting the endpoint with a double slash in the path, e.g.

curl http://localhost:8080//test/path/fubar

Then the request validation panics with

panic: runtime error: slice bounds out of range [1:0]

goroutine 1374 [running]:
github.com/pb33f/libopenapi-validator/parameters.(*paramValidator).ValidatePathParamsWithPathItem(0x11714f5626d0, 0x11714f3af040, 0x11714fb80000, {0x11714f33bd58, 0x12})
	/Users/oabdoun/go/pkg/mod/github.com/pb33f/libopenapi-validator@v0.13.7/parameters/path_parameters.go:86 +0x1f98
github.com/pb33f/libopenapi-validator.(*validator).ValidateHttpRequestWithPathItem.func1.2(0x11714f8be5b0, 0x11714f8be540, 0x0?)
	/Users/oabdoun/go/pkg/mod/github.com/pb33f/libopenapi-validator@v0.13.7/validator.go:257 +0x40
created by github.com/pb33f/libopenapi-validator.(*validator).ValidateHttpRequestWithPathItem.func1 in goroutine 1371
	/Users/oabdoun/go/pkg/mod/github.com/pb33f/libopenapi-validator@v0.13.7/validator.go:265 +0x37c```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions