Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S6931 FN: Route templates starting with ~/ #9002

Closed
antonioaversa opened this issue Apr 2, 2024 · 0 comments · Fixed by #9409
Closed

Fix S6931 FN: Route templates starting with ~/ #9002

antonioaversa opened this issue Apr 2, 2024 · 0 comments · Fixed by #9409
Assignees
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: False Negative Rule is NOT triggered when it should be.
Milestone

Comments

@antonioaversa
Copy link
Contributor

antonioaversa commented Apr 2, 2024

Route templates starting with ~/ seem to have an equivalent behavior to the ones starting with /: see here:

In the preceding code, the Index method templates must prepend / or ~/ to the route templates. Route templates applied to an action that begin with / or ~/ don't get combined with route templates applied to the controller.

If so, the following is a False Negative:

public class A2Controller : Controller
{
    [Route("~/B")]
    public IActionResult B3([FromQuery] Person person) => Content("Hello");
}

since the following is a True Positive:

public class A2Controller : Controller // Noncompliant
{
    [Route("/B")]
    public IActionResult B3([FromQuery] Person person) => Content("Hello");
}

Alternative: We may also decide to consider ~/ as a more explicit way than /, for the user to say that the route should actually be attached to the web-application route, and not to the controller one. In that case, we should add ~/ as an exception for S6931.

Test case: https://sourcegraph.com/github.com/bitwarden/server@b9049cd699e8a80c585346f9c53caa40f38133f2/-/blob/src/Api/Controllers/InfoController.cs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: False Negative Rule is NOT triggered when it should be.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants