diff options
author | Campbell Barton <campbell@blender.org> | 2022-11-02 06:07:54 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-11-02 06:11:46 +0300 |
commit | db43aa772925d4f6bd311858cd1ee4fe9aebc4e8 (patch) | |
tree | 80372c386d39e36b0217e49ae078ef4b0bb028a2 /source/blender/blenlib | |
parent | 5a90bbf71675651bd74cef435c0724e5b07a544c (diff) |
Fix T102201: File selector shows "\" before folder names on WIN32
Regression in [0] on WIN32 caused joining paths {"//", "path"} to
result in "//\path".
This made the file selector show paths with a "\" prefix.
Add an exception for WIN32 where an initial path of forward slashes
is joined without a back-slash.
[0]: 8f7ab1bf46d5e8610b167180b7631ff62e718a08
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index f46c2e65395..7c08eeedaa2 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1500,6 +1500,27 @@ size_t BLI_path_join_array(char *__restrict dst, return ofs; } +#ifdef WIN32 + /* Special case "//" for relative paths, don't use separator #SEP + * as this has a special meaning on both WIN32 & UNIX. + * Without this check joining `"//", "path"`. results in `"//\path"`. */ + if (ofs != 0) { + size_t i; + for (i = 0; i < ofs; i++) { + if (dst[i] != '/') { + break; + } + } + if (i == ofs) { + /* All slashes, keep them as-is, and join the remaining path array. */ + return path_array_num > 1 ? + BLI_path_join_array( + dst + ofs, dst_len - ofs, &path_array[1], path_array_num - 1) : + ofs; + } + } +#endif + /* Remove trailing slashes, unless there are *only* trailing slashes * (allow `//` or `//some_path` as the first argument). */ bool has_trailing_slash = false; |