Commit 7fd0aa5
committed
screenshot: fix %f corner case
URLs can end with trailing slashes (/) which in turn results in GNU
basename[1] returning the empty string. Catch that case and fallback on
the raw value of mpctx->filename. Subsequent path sanitation takes care
of translating invalid path component chars.
Issue reproduction steps:
```
mpv \
--screenshot-dir=$HOME/mpv-shots \
--screenshot-template='%f/%P' \
https://example.org/video/
```
This would result in %f expanding to '' and thus render
screenshot-template an absolute path which, for some reason, would in
turn take precedence of screenshot-dir and hence result in a
non-writeable path, i.e. `/timestamp.ext`.
With this new approach the resulting path looks like this:
`/home/user/mpv-shots/http:__example.org_video_/timestamp.ext`
Not particularly pretty but less ambiguous and more consistent over a
diverse range of input paths.
[1] #14635 (comment)1 parent 28ef6b7 commit 7fd0aa5
1 file changed
+10
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
| 178 | + | |
| 179 | + | |
183 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
184 | 189 | | |
185 | 190 | | |
186 | 191 | | |
| |||
300 | 305 | | |
301 | 306 | | |
302 | 307 | | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | 308 | | |
307 | 309 | | |
308 | 310 | | |
| |||
0 commit comments