Describe the bug
simplify()
does not reduce multiple leading path separators.
To Reproduce
Run this shell command:
vim -Nu NONE -es +"pu=simplify('//tmp')|%p" +'qa!'
The output is //tmp
.
Expected behavior
The output is /tmp
.
Environment
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
This is not a bug. The simplify() function should leave two leading
slashes alone.
Although, if the specification says that more than 2 leading slashes should be treated as a single slash, then maybe this could be considered as a bug:
echo simplify('///tmp')
///tmp
—
You are receiving this because you commented.
Ok, so the original MWE was wrong; Vim correctly follows the POSIX specification when a file path starts with 2 leading slashes, but not when a file path starts with more than 2 slashes. I updated the OP to fix the example.
—
You are receiving this because you commented.
Never mind. The spec is too complex. I'll need to read it later to check whether this is really a bug.
—
You are receiving this because you commented.
@brammool I have been following this issue, and I was hoping that there could be an optional parameter to remove all forward slashes at the front except for the first one.
This is because I am using paths as keys to a dictionary, and without simplify()
removing all leading duplicate forward slashes, there is no good option than adding unnecessary stuff.
These are the best two ways of doing it without this optional "remove all prefixed duplicate forward slashes":
let foo = function({ path -> simplify(path[:0] is '/' ? '//'..path : path) }(expand(a:path)
let foo = substitute(simplify(expand(a:path)), '^/\{2.}', '/', '')
I am not a big fan of either of these happening many times per second in a loop or in a repeatedly called function. let foo = simplify(a:path, v:true)
is much more preferable.
—
You are receiving this because you commented.
As it turns out, I am using the new readdirex()
which becomes the keys, so it shouldn't be a problem. using I shouldn't be using simplify
—
You are receiving this because you commented.