Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Request not matching route with defaults #324

Closed
kichalla opened this issue Jun 14, 2016 · 7 comments
Closed

Request not matching route with defaults #324

kichalla opened this issue Jun 14, 2016 · 7 comments
Assignees

Comments

@kichalla
Copy link
Member

A request like /api/test is resulting in 404. A request like /api/test/hello works fine as expected.

public class TestController : Controller
{
    [Route("api/test/{seg1=foo}")]
    public string onevariablesegmentwithdefaults(string seg1 = null)
    {
        return $"onevariablesegmentwithdefaults:{seg1}";
    }
}

This is working fine with RC2 final packages, so looks like a regression

@rynowak

@kichalla
Copy link
Member Author

@javiercn

@javiercn
Copy link
Member

I'll look at it.

@javiercn
Copy link
Member

I suspect this might have worked by chance in the previous code. I don't see tests for this, I'm guessing that /{controller=Home}/{action=index} or similar would not have worked in the previous version

@javiercn
Copy link
Member

I think I found the issue and a potential fix for it. We are not constructing the tree properly, when we have default parameters we don't put the route in the matches list of previous nodes on the tree.
I believe if (part.IsParameter && (part.IsOptional || part.IsCatchAll)) should be if (part.IsParameter && (part.IsOptional || part.IsCatchAll || part.DefaultValue != null)) on https://github.com/aspnet/Routing/blob/dev/src/Microsoft.AspNetCore.Routing/Tree/TreeRouteBuilder.cs#L336

I need to look deeper into the issue to make sure all scenarios are covered. I'll add more tests regarding default values, but I'm almost sure that in the previous version of the code it worked because we only tested one default parameter.

/cc @rynowak

@javiercn javiercn added this to the 1.0.1 milestone Jun 15, 2016
@javiercn javiercn self-assigned this Jun 15, 2016
@javiercn
Copy link
Member

Discussed this with @Eilon. Marked for 1.0.1 if you think otherwise voice your concerns @kichalla @rynowak

@mohsenamirkhani
Copy link

mohsenamirkhani commented Mar 3, 2018

how can we write somthing like this
[Route("api/test/{number=12:regex(\\d{2})}")]

@rynowak
Copy link
Member

rynowak commented Mar 4, 2018

Hi, it looks like you are posting on a closed issue/PR/commit!

We're very likely to lose track of your bug/feedback/question unless you:

  1. Open a new issue
  2. Explain very clearly what you need help with
  3. If you think you have found a bug, include detailed repro steps so that we can investigate the problem

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants