Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

br shell function does not escape file path #820

Open
proItheus opened this issue Jan 13, 2024 · 6 comments
Open

br shell function does not escape file path #820

proItheus opened this issue Jan 13, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@proItheus
Copy link

Broot's wrapping shell function does not escape file path, e.g. test'"$(, the shell will be crazy.

In regard to how to escape, a stackoverflow post says:

The only quoting method that is safe is ... single quoting of everything (even the empty string, even characters you'd imagine never to be a problem), and represent the single quote character itself as "'" or \' outside of the single-quotes

That is, test'" as 'test'\''" '

@proItheus proItheus added the bug Something isn't working label Jan 13, 2024
@Canop
Copy link
Owner

Canop commented Jan 13, 2024

What wrapping are you referring to ? Anything specific ? Can you please describe a complete failing case ?

@proItheus
Copy link
Author

proItheus commented Jan 13, 2024

Ah, sorry for being a bit ambiguous. By wrapping function I mean br shell function. A failing case:

mkdir \'
br

in shell, and

:focus '
alt+enter

in broot.

@proItheus proItheus changed the title Broot's wrapping shell function does not escape file path br shell function does not escape file path Jan 13, 2024
@proItheus proItheus changed the title br shell function does not escape file path br shell function does not escape file path Jan 13, 2024
@Canop
Copy link
Owner

Canop commented Jan 13, 2024

What shell are you using ? bash ?

@proItheus
Copy link
Author

I've tested fish and bash.

@proItheus
Copy link
Author

Oh, sorry again, that's not the case, the failed case should be '. Edited previous comment.

@AndydeCleyre
Copy link

This problem can now (>1.33.1) be avoided by using the following verb:

{
  key: alt-enter
  invocation: cd
  cmd: ":write_output {directory};:quit"
}

with the following launcher function (Bash) (only slightly tested):

function br {
    local path path_file code
    path_file=$(mktemp)
    if broot --verb-output "$path_file" "$@"; then
        path=$(<"$path_file")
        command rm -f "$path_file"
        if [[ -d "$path" ]]; then
          cd "$path"
        fi
    else
        code=$?
        command rm -f "$path_file"
        return "$code"
    fi
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants