Skip to content

string escape drops NUL and following text #4605

Closed

Description

@cben

fish, version 2.7.0-513-g81dd4a45
Linux, Fedora 27, gnome-terminal (TERM=xterm-256cotor).
Confirmed without customization (sh -c 'env HOME=$(mktemp -d) fish').

Actual behavior: string escape doesn't handle NUL:

/h/b/fish-shell> printf 'foo\0bar' | cat -A
foo^@bar⏎
/h/b/fish-shell> printf 'foo\0bar' | string escape
foo

and string unescape has similar problem:

/h/b/fish-shell> printf 'escaped\\0text' | string unescape
escaped

Expected behavior:

/h/b/fish-shell> printf 'foo\0bar' | string escape
foo\0bar
/h/b/fish-shell> printf 'escaped\\0text' | string unescape | cat -A
escaped^@text⏎

Generally, it should be possible to round-trip any binary data through | string escape | string unescape |.

Activity

  1. added
    bug
    on Dec 19, 2017
  2. added this to the fish-future milestone on Dec 19, 2017
  3. faho commented on Dec 19, 2017

    @faho
    Member

    Yup. The issue is that we're still using c-style strings all over the place. This might take a while to solve.

  4. ridiculousfish commented on Dec 25, 2017

    @ridiculousfish
    Member

    This is fixable in each individual case - if there's some particular case that's blocking you please let us know.

  5. faho commented on Jan 2, 2018

    @faho
    Member

    I've now implemented this in a branch for the "script" escaping style (see the commit linked above).

    Note that it's a bit hacky because it needs to get the wcstring, so I just added a method to get a reference to the arg_iterator_t's storage_, and since I still don't fully grok C++ reference lifetimes that might be not entirely correct.

    I want to implement it for the other escape styles as well before I merge it.

  6. added a commit that references this issue on Jan 3, 2018
    dbe62ea
  7. faho commented on Jan 11, 2018

    @faho
    Member

    I have now converted all string subcommands except for match and replace. Those are a bit trickier because of the interactions with pcre.

    Also, as it turns out escape, unescape, upper and lower have a bunch of duplicated code - the latter two do the exact same thing except one passes "std::towupper" and the other "std::towlower".

  8. modified the milestones: fish-future, on May 28, 2018
  9. locked as resolved and limited conversation to collaborators on Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions