question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not work with unicode as input

See original GitHub issue

Example code as below:

def MyCompleter(prefix, **kwargs):
    results = ['aaa', 'bbb']
    return (c for c in results if c.startswith(prefix))

if __name__ == '__main__':
    import argparse
    import argcomplete

    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers(dest='command')
    create_parser = subparsers.add_parser('new')
    create_parser.add_argument('title')
    create_parser.add_argument('category').completer = MyCompleter
    argcomplete.autocomplete(parser)
    args = parser.parse_args()
    print args

It works as expect when all the inputs are normal characters (assume above code are wrapped in command demo):

$ ./demo.py new 'hi'
--help  -h      aaa     bbb  

When the input contains unicode, the auto completer is not working:

$ ./demo.py new '你好'

So, is this a bug or something related to the shell? I’m using zsh and argcomplete (Version: 1.9.2).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16

github_iconTop GitHub Comments

1reaction
evanunderscorecommented, Sep 4, 2017

It looks like zsh is being smarter than bash and giving COMP_POINT in unicode chars instead of bytes. When we incorrectly interpret that number, we end up slicing the input halfway through a character, which we then fail to decode. Even if that didn’t crash, the results would likely be undesirable.

I used bashcompinit as described here to reproduce this. I’m assuming bashcompinit is supposed to emulate bash completion, in which case I’d say this should be considered a bug on their end.

On the other hand, the documentation for COMP_POINT explicitly says “If the current cursor position is at the end of the current command, the value of this variable is equal to ${#COMP_LINE}.” So bashcompinit is adhering to the spec and bash is not.

0reactions
evanunderscorecommented, Nov 21, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

Hex Unicode input not working in Microsoft apps
I have input unicode text before with the method: hold [alt], [numeric plus]+[Unicode ... Hex Unicode input not working in Microsoft apps.
Read more >
Unicode escape not working with user input - Stack Overflow
I have a short python script that's supposed to print the unicode character from a number the user inputs. However, ...
Read more >
hexadecimal unicode input broken - Apple Community
The trick is that you have to use the numeric keypad. Hold down alt, press +, and then enter the value that you...
Read more >
How to enter Unicode characters in Microsoft Windows
Method 2: Input-language Specific · Press and hold down the Alt key. · Type 0 (zero) and the decimal unicode value on the...
Read more >
Unicode input - Wikipedia
Unicode input is the insertion of a specific Unicode character on a computer by a user; it is a common way to input...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found