[vim/vim] "simplify()" does not reduce multiple leading path separators (#6263)

9 views
Skip to first unread message

lacygoill

unread,
Jun 15, 2020, 12:02:51 PM6/15/20
to vim/vim, Subscribed

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

  • Vim version: 8.2 Included patches: 1-981
  • OS: Ubuntu 16.04.6 LTS
  • Terminal: XTerm(322)


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Gary Johnson

unread,
Jun 15, 2020, 12:54:44 PM6/15/20
to reply+ACY5DGCKRAVUIRK6CS...@reply.github.com, vim...@googlegroups.com
On 2020-06-15, lacygoill wrote:
> 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
>
> • Vim version: 8.2 Included patches: 1-981
> • OS: Ubuntu 16.04.6 LTS
> • Terminal: XTerm(322)

This is not a bug. The simplify() function should leave two leading
slashes alone. The POSIX spec states:

A pathname that begins with two successive slashes may be
interpreted in an implementation-defined manner, although more
than two leading slashes shall be treated as a single slash.

Regards,
Gary

----------
http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap04.html#tag_04_11
https://unix.stackexchange.com/questions/12283/unix-difference-between-path-starting-with-and

vim-dev ML

unread,
Jun 15, 2020, 12:55:03 PM6/15/20
to vim/vim, vim-dev ML, Your activity

On 2020-06-15, lacygoill wrote:
> 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
>
> • Vim version: 8.2 Included patches: 1-981
> • OS: Ubuntu 16.04.6 LTS
> • Terminal: XTerm(322)

This is not a bug. The simplify() function should leave two leading
slashes alone. The POSIX spec states:

A pathname that begins with two successive slashes may be
interpreted in an implementation-defined manner, although more
than two leading slashes shall be treated as a single slash.

Regards,
Gary

----------
http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap04.html#tag_04_11
https://unix.stackexchange.com/questions/12283/unix-difference-between-path-starting-with-and

lacygoill

unread,
Jun 15, 2020, 12:59:01 PM6/15/20
to vim/vim, vim-dev ML, Comment

Closed #6263.


You are receiving this because you commented.

lacygoill

unread,
Jun 15, 2020, 2:35:30 PM6/15/20
to vim/vim, vim-dev ML, Comment

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.

Gary Johnson

unread,
Jun 15, 2020, 2:55:06 PM6/15/20
to reply+ACY5DGGXMOMLJDCDZN...@reply.github.com, vim...@googlegroups.com
On 2020-06-15, lacygoill wrote:
> 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

I later thought about that, too. I think you're probably right.
I'm not aware of any cases where more that two slashes has any
meaning, and POSIX says they should be treated as one, so it would
make sense for simplify() to collapse more than two to just one.

Regards,
Gary

vim-dev ML

unread,
Jun 15, 2020, 2:55:29 PM6/15/20
to vim/vim, vim-dev ML, Your activity

lacygoill

unread,
Jun 15, 2020, 3:05:06 PM6/15/20
to vim/vim, vim-dev ML, Comment

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.

lacygoill

unread,
Jun 15, 2020, 3:05:07 PM6/15/20
to vim/vim, vim-dev ML, Comment

Reopened #6263.


You are receiving this because you commented.

lacygoill

unread,
Jun 15, 2020, 3:08:00 PM6/15/20
to vim/vim, vim-dev ML, Comment

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.

lacygoill

unread,
Jun 15, 2020, 3:08:01 PM6/15/20
to vim/vim, vim-dev ML, Comment

Closed #6263.


You are receiving this because you commented.

dylnmc

unread,
Jun 15, 2020, 4:35:12 PM6/15/20
to vim/vim, vim-dev ML, Comment

@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.

Gary Johnson

unread,
Jun 15, 2020, 5:02:50 PM6/15/20
to reply+ACY5DGC7ORTLNI4BPW...@reply.github.com, vim...@googlegroups.com
On 2020-06-15, dylnmc wrote:
> @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.

So what is the measured performance difference of

let foo = simplify(expand(a:path)

vs.

let foo = substitute(simplify(expand(a:path)), '^/\{2.}', '/', '')

in your application?

Regards,
Gary

vim-dev ML

unread,
Jun 15, 2020, 5:03:13 PM6/15/20
to vim/vim, vim-dev ML, Your activity

dylnmc

unread,
Jun 16, 2020, 2:19:16 PM6/16/20
to vim/vim, vim-dev ML, Comment

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.

Reply all
Reply to author
Forward
0 new messages