Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

[#732] Attribute Routing: Implement ~/ for overriding a prefix #761

Closed
wants to merge 5 commits into from

Conversation

javiercn
Copy link
Member

@javiercn javiercn commented Jul 8, 2014

This change allows a user to override a route prefix set using
[Route("...")] on the controller by providing a route template
on the action that starts with "/" or "/". For example,
[HttpGet("
/...")] or [HttpGet("/...")]

If the user specifies a template in [Route] that starts with "~/"
or "/", we will just strip the prefix from the template and use
the remaining part of the template.

The reason to do this is that there's a reasonable extensibility
scenario where a user can implement a global prefix for routes as
a convention (using IReflectedApplicationModelConvention), and use
~/ to escape that prefix (just like we support with action-level routes).

@javiercn
Copy link
Member Author

javiercn commented Jul 8, 2014

@rynowak @yishaigalatzer This is the right place to comment.


if (trimmedLeft == string.Empty)
{
return trimmedRight;
return right;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems broken. Consider Combine("~/", "Blog/Index/"). The right side won't get trimmed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it and added a test case for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're returning right here not trimmedRight

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you add the testcase that I included above

@yishaigalatzer yishaigalatzer added this to the 6.0.0-alpha3 milestone Jul 8, 2014
@yishaigalatzer
Copy link
Contributor

#732

@rynowak
Copy link
Member

rynowak commented Jul 8, 2014

:shipit:

public async Task AttributeRoutedAction_ActionLevelRouteWithTildeSlash_OverridesControllerLevelRoute()
{
// Arrange
var server = TestServer.Create(_services, _app);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test where the base path of the application has a VDir path...example: the request url is like http://localhost/MyApp/Manager/5?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open a bug, that's a good thing to have, but unrelated to this work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javiercn : can you open a bug for this...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks.. :shipit:

@pranavkm
Copy link
Contributor

pranavkm commented Jul 9, 2014

:shipit:

@@ -22,16 +24,25 @@ public static string Combine(string left, string right)
}
else if (left == null)
{
return right.Trim('/');
return right.TrimStart('~').Trim('/');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't do this. You create two extra strings in the process. Make a single helper to trim ~/ or / and use it

javiercn added 5 commits July 9, 2014 17:31
This change allows a user to override a route prefix set using
[Route("...")] on the controller by providing a route template
 on the action that starts with "~/" or "/". For example,
 [HttpGet("~/...")] or [HttpGet("/...")]

If the user specifies a template in [Route] that starts with "~/"
or "/", we will just strip the prefix from the template and use
the remaining part of the template.

The reason to do this is that there's a reasonable extensibility
scenario where a user can implement a global prefix for routes as
a convention (using IReflectedApplicationModelConvention), and use
~/ to escape that prefix (just like we support with action-level routes).
1) Updated StartsWith calls to use StringComparer.OrdinalIgnoreCase.
2) Trim the end of the right part of a template when it doesn't start
   with "/" or "~/" and added tests to cover both scenarios.
3) Fixed the format of tests to move all asserts before an // Assert
   comment after it, and remove aditional // Assert comments from the
   tests.
… calls

and substituted the cleanup for removing starting "/" and "~/" prefixes and
"/" suffix from the combined template.
@yishaigalatzer
Copy link
Contributor

:shipit:

@javiercn
Copy link
Member Author

commit 87c430a

@javiercn javiercn closed this Jul 16, 2014
@javiercn javiercn deleted the issue732 branch July 16, 2014 16:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants