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

CaptureAll #1516

Merged
merged 5 commits into from
Feb 9, 2024
Merged

CaptureAll #1516

merged 5 commits into from
Feb 9, 2024

Conversation

guygastineau
Copy link
Contributor

closes #1243

In the end it was a simple fix, but new tests were necessary. I also modified the existing tests for the original test API for CaptureAll. Using the sum of a list let the bug from #1243 linger. Now the tests will catch any regressions. I am not sure if there.

I tried combining the "rooted" capture all API at the end of the legs and arms API, but then it caught the parsing failure tests for the leg route, so I figured it might as well be another router.

I tried to be tidy.

  * This fails two of the tests.  We should probably add a catch all
    at the end that captures anything not matches by the Symbols for
    the preceding branches `arms` and `legs`.
  * When using `CaptureAll` from the root "/" and empty path becomes
    an empty list.  when using it from a branch though an empty path,
    ie. a trailing separator, becomes `mempty` for the type.  Where is
    this happening?  I think this is definitely happening before
    `parseUrlpieces` gets run, so it happens in the machinery for
    Delayed and DelayedIO.  I am still looking for the code that
    produces the `txts` argument for the `captureD` lambda created in
    the `HasServer` instance for `CaptureAll`.
  * Routes ending in a `CaptureAll` now get an empty list instead of
    [""] when they have a trailing slash.
  * WARNING: I think this will break the expectation that a rooted
    capture all will produce [""] for `//`.  That is, previously `// =>
    [""]`, but I think `// => []`.  I will make some tests to check
    and see what is going on with this.
  * Trailing slashes will no longer affect the captures for "rooted"
    CaptureAll apis (test included).
@guygastineau
Copy link
Contributor Author

@domenkozar please let us know if this solves your issue.

@guygastineau
Copy link
Contributor Author

This PR does change the data processed by handlers for CaptureAll apis. This might mean some kind of breaking change. The difference is:

// was ["", ""], but now it is [""]
/some-route/ was [""], but now it is []
/some-route// was ["", ""], but now it is [""]

@guygastineau
Copy link
Contributor Author

I forgot to make a file in changeling.d. sorry

guygastineau added a commit to guygastineau/servant that referenced this pull request Jan 25, 2022
@guygastineau guygastineau changed the title Captureall CaptureAll Jan 25, 2022
@alpmestan
Copy link
Contributor

FWIW, The new behaviour seems more correct to me.

@guygastineau
Copy link
Contributor Author

@alpmestan great. The side by side string and int tests might be redundant. Or maybe the community wants new tests? I think I got the tests we need to understand my change and prevent regression, but I'd love if someone tried to poke holes in that confidence.

Copy link
Contributor

@alpmestan alpmestan left a comment

Choose a reason for hiding this comment

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

Just a typo, otherwise LGTM.


description: {

CaptrueAll resulted in `[""]` for empty paths due to trailing slash. Similar
Copy link
Contributor

Choose a reason for hiding this comment

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

CaptureAll *

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks you. I'll get the typo fixed this afternoon EST.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I forgot to get to this. I'll get it today.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I amended and force pushed. Apologies to anyone who might have fetched my branch.

@alpmestan
Copy link
Contributor

CI jobs running now. If it goes through, this is IMO good to go. @akhesaCaro @gdeest @tchoutri Your opinion?

Copy link
Contributor

@tchoutri tchoutri left a comment

Choose a reason for hiding this comment

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

I'm overall satisfied with this PR, thank you very much for the feature. :)

@@ -178,7 +178,10 @@ runRouterEnv fmt router env request respond =
-> let request' = request { pathInfo = rest }
in runRouterEnv fmt router' (first, env) request' respond
CaptureAllRouter router' ->
let segments = pathInfo request
let segments = case pathInfo request of
-- this case is to handle trailing slashes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Good thinking

@guygastineau
Copy link
Contributor Author

guygastineau commented Feb 9, 2024

Is there a reason why this hasn't been merged yet other than everyone being busy and letting slip through the cracks?

It has merge conflicts now. Should I fix that on my end?

@domenkozar domenkozar merged commit 740bca7 into haskell-servant:master Feb 9, 2024
8 checks passed
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.

empty path when using CaptureAll results to [""]
4 participants