Skip to content

Wrong route chosen for match any routes on multiple levels #1412

Closed
@lammel

Description

@lammel

Issue Description

For match any routes configured on multiple levels the wrong route seems to be chosen.

It is expected that if a route is not found, that the nearest (longest matching) match any route is chosen.

For the following defined routes

/api/user
/api/*
/*

it would be expected for any request under /api that can not be resolved to return the match any /api/* route, even those under /api/user/something.
This is currently handled for static only routes that way.

A PR will be opened to resolve this issue (probably alongside with #1406).

Checklist

  • Dependencies installed
  • No typos
  • Searched existing issues and docs

Expected behaviour

The route /api/* will be chosen

Actual behaviour

A not found is returned for /api/user/notexists

Steps to reproduce

Run example below.

Working code to debug

package main

import (
	"net/http"
	"github.com/labstack/echo/v4"
)

func main() {
	// Echo instance
	e := echo.New()

	// Routes
	e.GET("/admin", func(c echo.Context) error { return c.String(http.StatusOK, "admin") })
	e.GET("/api/help", func(c echo.Context) error { return c.String(http.StatusOK, "api help") })
	e.GET("/api/*", func(c echo.Context) error { return c.String(http.StatusOK, "api any") })
	e.GET("/*", func(c echo.Context) error { return c.String(http.StatusOK, "root any") })
	
	// Start server
	e.Logger.Fatal(e.Start(":1323"))
}

Version/commit

Tested with v4.1.10

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