serokell / coffer

Multi-backend password store with multiple frontends
4 stars 2 forks source link

Show strings escaped in error messages #49

Closed dcastro closed 2 years ago

dcastro commented 2 years ago

Clarification and motivation

Error messages about invalid characters in paths/field names/tags should show the string escaped.

Imagine the user copy-pastes some text that happens to contain the "zero width space" unicode character (\xE2\x80\x8B in utf-8 hex notation), and uses that text in the path in coffer create.

This character is completely invisible, but coffer will (correctly) reject it.

At the moment, because we don't escape it, this is what the user will see:

$ coffer create "$(echo "hello\xE2\x80\x8Bthere")"
Invalid entry path: 'hellothere'.
Path segments can only contain the following characters: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'

Usage: coffer create ENTRYPATH [-e|--edit] [-f|--force] [--tag TAG] 
                     [--field NAME=CONTENT] [--privatefield NAME=CONTENT]
  Create a new entry at the specified path

This will just leave the user scratching their head - we're telling them the path has invalid characters, but all the characters shown on the screen are valid!

To avoid this, we should display invalid paths/field names/tags with all characters escaped.

Acceptance criteria