-
Notifications
You must be signed in to change notification settings - Fork 3.2k
misc/path_utils: make mp_basename() return full URLs #17022
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
base: master
Are you sure you want to change the base?
Conversation
When the path is a URL, use the whole path as basename. The dirname will be "." in this case. This simplifies various checks throughout the codebase. In particular, it avoids returning an empty string for URLs ending with /. The filename property will return full URLs, which is desirable because the domain and path segments before the last are useful information. This fixes half of mpv-player#10975. This also fixes the issue described in mpv-player#17015 of %f in --screenshot-template being evaluated to an empty string for URLs ending with /, which can inadvertently make it use an absolute path. Alternative to mpv-player#16932 and mpv-player#17021.
9e9319e to
65e5abb
Compare
|
This does alter the semantics of |
|
Use by who? This is an internal mpv function. And using the same function only simplifies the code already using it by just removing conditions, no calls in the codebase benefitted from returning the basename of URLs. |
|
Fair enough. I was just musing about people not intimately familiar with the code base. Seeing something that says basename and not looking at its implementation may yield unexpected results. I am thinking about the concept of encapsulation when I talk about not looking at the code of a until function. Ideally, what it does is obvious from the outside, so it might as well be black box. |
|
It doesn't matter what's expected when everywhere in the codebase benefits from keeping full URLs, including the implementation of |
|
But there may be. Imagine some passerby wanting to contribute something related. They can find a monolithic function that does everything perfectly for a narrow set of problem or they can find a wrapper that does exactly the same, but its building block(s), with well defined behavior in case of GNU basename, there for the taking. |
| char *mp_basename(const char *path) | ||
| { | ||
| if (mp_is_url(bstr0(path))) | ||
| return (char *)path; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as an aside: why does this function not return a const char*?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently it did until 962eec0 with no explanation for the change. Anyway, I can change it after this PR.
Before the previous commit stripext(), used for %F, was passed the basename of URLs. Now that full URLs are passed, make it use mp_splitext which handles extensions in URLs correctly, e.g. with "https://example.com/foo" it returns NULL instead of "com/foo", and it is even less code than before. ${filename/no-ext} was already using mp_splitext().
|
Download the artifacts for this pull request: Windows |
|
The problem with this idea is that |
When the path is a URL, use the whole path as basename. The dirname will be "." in this case.
This simplifies various checks throughout the codebase. In particular, it avoids returning an empty string for URLs ending with /.
The filename property will return full URLs, which is desirable because the domain and path segments before the last are useful information. This fixes half of #10975.
This also fixes the issue described in #17015 of %f in --screenshot-template being evaluated to an empty string for URLs ending with /, which can inadvertently make it use an absolute path.
Alternative to #16932 and #17021.