Distinguish empty path from literal slash in Url.lastSegment - #2797
Distinguish empty path from literal slash in Url.lastSegment#2797xhon-pelushi wants to merge 2 commits into
Conversation
Return null when a URL has no path segments so a remote member named \"/\" (decoded from %2F) is not conflated with the empty-path sentinel. Display sites keep the \"/\" fallback; sync paths treat null as missing. Fixes bitfireAT#2782
rfc2822
left a comment
There was a problem hiding this comment.
Hi,
Thanks for the efforts. Was the concept of this PR done by AI?
There are two additional helpers in dav4jvm:
Response.hrefNameHttpUtils.fileName
Should we use / unify / drop those?
I think at the end we should have only one method to get the file name from an Url, it it should be always the same.
| * otherwise be path separators. | ||
| */ | ||
| val fileName: String | ||
| val fileName: String? |
There was a problem hiding this comment.
I think a member should always have a file name. If it doesn't, it's not an (internal / direct) member.
So InternalMemberState should never be created without a proper file name.
Then all the require would fall away.
Delegate Url.lastSegment to dav4jvm HttpUtils.fileName so empty paths are "" and a literal "/" segment stays "/". Keep InternalMemberState fileName non-null by filtering members without a name at construction. Fixes bitfireAT#2782
|
Thanks for the feedback — pushed a follow-up that unifies this with dav4jvm:
On the design concept: the goal was specifically to stop conflating “no path” with a resource literally named |
|
Thanks @rfc2822 — follow-up commit unifies on
I used tooling while exploring the helpers; happy to adjust further if you want |
Summary
Url.lastSegmentreturnnullfor URLs with no path segments instead of"/"."/"when the last segment literally decodes to a slash (%2F).?: "/"; sync/InternalMemberStatetreat null as missing so a member named/cannot collide with the empty-path sentinel.Fixes #2782
Test plan
./gradlew :core:testDebugUnitTest --tests 'at.bitfire.davdroid.util.DavUtilsTest'/for empty-path homesets.