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

:A modifier reacts badly to pattern meta-characters #7

Open
okdana opened this issue Jul 2, 2018 · 0 comments
Open

:A modifier reacts badly to pattern meta-characters #7

okdana opened this issue Jul 2, 2018 · 0 comments
Labels
bug unacknowledged Reported but unacknowledged on the ML

Comments

@okdana
Copy link
Owner

okdana commented Jul 2, 2018

(workers/42259)

Hey there. I ran into the following problem today:

% print -r ${${:-a-b}:a}
/Users/dana/a-b
% print -r ${${:-a-b}:A}
/Users/dana/a?b

The ? in the second one is 0x9b (Dash).

Both chabspath() (:a) and chrealpath() (:A) receive the input as $'a\x9bb'. :a
doesn't care, because all it's doing is manipulating . and / in the string.
It is a concern for :A, though, because it has to pass the string to realpath(),
and then it has to metafy() the result. There are two related issues, then:

  1. chrealpath() can't resolve paths passed into it this way if they contain
    pattern meta characters (any of them, not just -). It calls unmetafy(), but
    that doesn't help here.

  2. chrealpath() metafies the result at the end, converting (e.g.) $'.../a\x9bb'
    into $'.../a\x83\xbbb', which breaks the expansion even in cases where it'd
    be accidentally correct (like the one above).

(Quoting/escaping the expansion works around these. So does assigning 'a-b' to a
variable first, as long as you don't do something like ${${~str}:A}.)

Simply having chrealpath() call untokenize() after unmetafy() fixes the above
test case, but then there's a new problem: ${:-a-b} and ${:-$'a\x9bb'} are
indistinguishable to the function and thus give the same result. This would
break resolution of multi-byte file names, as in ${${:-ツ}:A} ( = $'\u30c4' =
$'\xe3\x83\x84').

Just to clarify, both :a and :P seem unaffected, though in :a's case it seems like it only gets it right by accident. I didn't check the actual code for :P.

@okdana okdana added bug unacknowledged Reported but unacknowledged on the ML labels Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unacknowledged Reported but unacknowledged on the ML
Projects
None yet
Development

No branches or pull requests

1 participant