热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Specialcharactersnotescapedforzshcompletionscript

RustVersionrustc1.38.0(625451e372019-09-23)AffectedVersionof


Rust Version

rustc 1.38.0 (625451e37 2019-09-23)

Affected Version of clap

clap 2.33.0

Expected Behavior Summary

Generated Zsh completions correctly complete

1
possible_values

even in the presence of characters that have a special meaning for the shell

Actual Behavior Summary

For example, when some string in

1
possible_values

contains

1
|

(a pipe) the generated completion script fails with

1
(eval):1: parse error near `|'

when pressing tab for that argument.
That was the problem I ran into. I then tested some other special characters.

A sample of the characters I found to have problems:
-

1
|

breaks completion script

1
(eval):1: parse error near `|'

-

1
;

splits completion value into two
-

1
?

makes whole value not show up in completions
-

1
*

makes whole value not show up in completions
-

1
"

breaks completion script

1
(eval):1: unmatched "

-

1
`

breaks completion script

1
(eval):1: unmatched `

-

1
$

interpreted as https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html when followed by some other chars
-

1
#

makes whole value not show up in completions

There are more special characters, that need to be escaped. The reproduction from the repo tests against all non control ascii characters and some dollar-something strings.

Steps to Reproduce the issue


  • Clone reproduction repo
    1
    git clone https://github.com/succcubbus/clap-zsh-completions-repro



  • 1
    cd clap-zsh-completions-repro



  • 1
    cargo run --release > _clap-zsh-completions-repro


  • Copy
    1
    _clap-zsh-completions-repro

    somewhere into the

    1
    $fpath

    of the zsh (e.g.

    1
    /usr/local/share/zsh/site-functions

    )



  • 1
    cargo install --path .



  • 1
    rehash; compinit

    (so the zsh picks up the new binary and completions)


  • Type
    1
    clap-zsh-completions-repro

    and try to complete the argument


Sample Code or Link to Sample Code

https://github.com/succcubbus/clap-zsh-completions-repro

Debug output

https://pastebin.com/KU4yd6FR

该提问来源于开源项目:clap-rs/clap

But I don't think there are any crates that do this.





   



推荐阅读
author-avatar
鬼鬼太子_157
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有