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

Escape a Little Less #449

Merged
merged 2 commits into from
Apr 30, 2019
Merged

Escape a Little Less #449

merged 2 commits into from
Apr 30, 2019

Conversation

chrisoverzero
Copy link
Contributor

@chrisoverzero chrisoverzero commented Apr 25, 2019

Issue Number

#440

Description of Changes

Double-escapes '%2F' so that it survives unescaping by WebUtility.UrlDecode. This matches other implementations better, and allows path parameters containing '%2F' (or '%2f', natch) to be routed correctly by ASP.NET Core. If someone suggests a smarter solution, I'll accept it happily. (Also some smaller changes, hopefully uncontroversial, all in a separate commit.)

License Acceptance

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. ✔️

This matches other implementations better, and allows path parameters
containing '%2F' (or '%2f', natch) to be routed correctly by ASP.NET
Core.

Fixes #440
- Corrects Spelling of Internal Method Name
- Uses `StringBuilder`'s `Append` Method More Efficiently
  - This is an attempt to pay back some string-manipulation tax paid
    in the feature commit of this PR.
- Restores Lost Chainable Contructors of
  `ApiGatewayProxyFunction<TStartup>`
  - Bug and fix written by the same developer.

Fixes #440
@normj
Copy link
Member

normj commented Apr 27, 2019

Thanks for the PR. Would you mind providing some example resource paths to the conversation? I'll add some test cases.

@chrisoverzero
Copy link
Contributor Author

chrisoverzero commented Apr 27, 2019

Oh, yes. Of course.

Given the routes:

  • [HttpGet("{first}/{second}", Name = "Multi")]
  • [HttpGet("{only}", Name = "Single")]

…in a TestsController:

  • /tests/a/b should route to "Multi"
    • with first = "a", second = "b"
    • which is a regression check
  • /tests/a%2Fb should route to "Single"
    • with only = "a%2Fb"
    • where routing to "Multi" is an error
  • /tests/a%2fb should route to "Single"
    • with only = "a%2fb"
    • where routing to "Multi" is an error

(Doing this from memory on a tablet, so please forgive minor errors.)

@normj
Copy link
Member

normj commented Apr 29, 2019

I was trying those resource paths using on a regular ASP.NET Core running on Kestrel and I'm seeing the results go into"Multi" request handler. Am I missing something?

@chrisoverzero
Copy link
Contributor Author

I can't recreate your results. From a fresh dotnet new webapi project, with this controller:

[Route("api/[controller]"), ApiController]
public class ValuesController : ControllerBase
{
    [HttpGet("{first}/{second}", Name = "Multi")]
    public ActionResult Multi(string first, string second) => Ok(new { first, second });

    [HttpGet("{only}", Name = "Single")]
    public ActionResult Single(string only) => Ok(new { only });
}

I get this:

cosborn@DEVCOSBORN1 MINGW64 /d/vp/routing-test
$ curl -sS 'http://localhost:5000/api/values/a/b'
{"first":"a","second":"b"}
cosborn@DEVCOSBORN1 MINGW64 /d/vp/routing-test
$ curl -sS 'http://localhost:5000/api/values/a%2Fb'
{"only":"a%2Fb"}

Gimme a few, and I'll get this into a git cloneable place.

@chrisoverzero
Copy link
Contributor Author

@normj
Copy link
Member

normj commented Apr 30, 2019

I figured out why I wasn't seeing the same behavior as you. If you run the ASP.NET Core behind IIS Express you get different behavior then just running it standalone through kestrel.

@normj
Copy link
Member

normj commented Apr 30, 2019

This has been merged into the dev branch 0965c3b

I'll chime back here when the change is released.

@normj normj merged commit f4173a1 into aws:master Apr 30, 2019
@normj
Copy link
Member

normj commented May 1, 2019

Version 3.0.4 is released with this PR. Thanks for the PR!

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

Successfully merging this pull request may close these issues.

2 participants