Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [bug] escaping spaces in _canonical_paths



Bart Schaefer wrote on Thu, Mar 09, 2017 at 21:48:20 -0800:
> On Mar 6, 10:16am, Philipp G. Haselwarter wrote:
> }
> } however, if I cd into /mnt and then try to umount the relative path
> } 
> } # cd /mnt
> } # umount nam
> } 
> } it gets completed to
> } 
> } # umount name with spaces
> } 
> } with no escapes for the spaces.
> 
> This seems to do it, although I haven't figured out why it is necessary
> to do the quote manipulation in the shell code here when it is not needed
> in the other (absolute-path) branch.

Perhaps the abspath branch gets confused on mountpoint names that
contain literal ' characters?  Since the ${foo/bar/baz} replacement is
done on the compadd results, and compadd wasn't called with -Q.

(Can't test this right now)

> diff --git a/Completion/Unix/Type/_canonical_paths b/Completion/Unix/Type/_canonical_paths
> index 6eab7b6..630907b 100644
> --- a/Completion/Unix/Type/_canonical_paths
> +++ b/Completion/Unix/Type/_canonical_paths
> @@ -41,7 +41,11 @@ _canonical_paths_add_paths () {
>      # ### Ideally, this codepath would do what the 'if' above does,
>      # ### but telling compadd to pretend the "word on the command line"
>      # ### is ${"the word on the command line"/$origpref/$canpref}.
> -    matches+=(${${(M)files:#$canpref*}/$canpref/$origpref})
> +    if [[ -z $compstate[quote] ]]; then
> +      matches+=(${(q)${(M)files:#$canpref*}/$canpref/$origpref})
> +    else
> +      matches+=(${${(M)files:#$canpref*}/$canpref/$origpref})
> +    fi
>    fi
>  
>    for subdir in $expref?*(@); do
> @@ -84,7 +88,7 @@ _canonical_paths() {
>      files+=($@:P)
>    fi
>  
> -  local base=$PREFIX
> +  local base=${(Q)PREFIX}
>    typeset -i blimit
>  
>    _canonical_paths_add_paths $base



Messages sorted by: Reverse Date, Date, Thread, Author