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

💥 matchRawUrl of PathSegment now demands that full path is matched #25

Merged
merged 1 commit into from
Dec 26, 2024

Conversation

sherpal
Copy link
Owner

@sherpal sherpal commented Dec 21, 2024

Previously, the matchRawUrl method of PathSegment would succeed if there were unused segments in the path.

We change that behaviour in such a way that matchRawUrl now fails if there are unused segments after applying the path. Users who want to go back to the old behaviour should use the new ignoreRemaining method.

See issue

Main attention points:

@sherpal sherpal linked an issue Dec 21, 2024 that may be closed by this pull request
@sherpal sherpal force-pushed the breaking-matchRawUrl-change branch from 891596e to 5847668 Compare December 21, 2024 12:58
Copy link
Contributor

@raquo raquo left a comment

Choose a reason for hiding this comment

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

Nice, This seems fine! Just some small comments.


You mentioned:

unfortunately I will need to embed the endOfSegmentRequired within the pathsegment...

Just FTR, I'm gonna confess that the reason why it's unfortunate escapes me at the moment – perhaps I haven't looked deeply / intently enough. You definitely know this project better though, especially the error handling that I've never really used, so if that part looks ok to you, that's good enough for me 👍

val remainingSegments: PathSegment[List[String], A] = PathSegment.remainingSegments
lazy val root: PathSegment[Unit, A] = PathSegment.root
lazy val remainingSegments: PathSegment[List[String], A] = PathSegment.remainingSegments
lazy val ignoreRemaining: PathSegment[Unit, A] = remainingSegments.ignore(Nil)
lazy val endOfSegments: PathSegment[Unit, A] = PathSegment.endOfSegments
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably @deprecate endOfSegments since there is no more use for it... or is there?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ah yes I wanted to do that, thanks

val remainingSegments: PathSegment[List[String], A] = PathSegment.remainingSegments
lazy val root: PathSegment[Unit, A] = PathSegment.root
lazy val remainingSegments: PathSegment[List[String], A] = PathSegment.remainingSegments
lazy val ignoreRemaining: PathSegment[Unit, A] = remainingSegments.ignore(Nil)
Copy link
Contributor

@raquo raquo Dec 21, 2024

Choose a reason for hiding this comment

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

Naming comment: hmm ignoreRemaining seems unclear on its own – remaining what? Especially when used as a property, without the /. Maybe ignoreRemainingSegments? – even if it's a mouthful, it would be clearer and consistent. Usages of it should be pretty rare anyway...

Eh TBH not super sure about this. I can see either way being fine. It just seems that ignoreRemaining was chosen to be consistent with the def ignore name, but as I mentioned in another comment, we probably shouldn't have def ignoreRemaining in the first place. So if that method does go away, perhaps naming should be realigned to be consistent with remainingSegments.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I chose ignoreRemaining over ignoreRemainingSegments because I thought it was too long, but that's indeed not a good point. It's better to be more explicit.

@@ -169,19 +193,21 @@ trait PathSegment[T, +A] extends UrlPart[T, A] {
(_: Unit) => createSegments(default)
)

final def ignoreRemaining: PathSegment[T, A] = this / PathSegment.remainingSegments.ignore(Nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

This method seems a bit out of place / redundant, no? The other non-symbolic methods here (like ignore) are about modifying the handling of the current segment or path, whereas def ignoreRemaining just appends another segment – but we already have / syntax for that.

Comment on lines 8 to 9
pathSegment: PathSegment[PathType, PathError],
queryParams: QueryParameters[ParamsType, ParamsError]
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're making breaking changes, could you please expose these constructor params as val? Or is there a good reason not to? I feel like this will eventually come in handy for route transformations in Waypoint...

Previously, the `matchRawUrl` method of `PathSegment` would succeed if there were unused segments in the path.

We change that behaviour in such a way that `matchRawUrl` now **fails** if there are unused segments after applying the path.
Users who want to go back to the old behaviour should use the new `ignoreRemaining` method.

See [issue](#24)
@sherpal sherpal force-pushed the breaking-matchRawUrl-change branch from 5847668 to 78721e8 Compare December 21, 2024 15:09
@sherpal sherpal marked this pull request as ready for review December 26, 2024 15:57
@sherpal sherpal merged commit b556173 into master Dec 26, 2024
1 check passed
@sherpal sherpal deleted the breaking-matchRawUrl-change branch December 26, 2024 15:57
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.

endOfSegments should be the default behaviour
2 participants