zsh-workers
 help / color / mirror / code / Atom feed
From: dana <dana@dana.is>
To: zsh-workers@zsh.org
Subject: [BUG] Issue with pattern meta characters passed to :A
Date: Fri, 12 Jan 2018 15:56:38 -0600	[thread overview]
Message-ID: <8FFCB628-DDE5-4FE7-B879-A6B4366B896E@dana.is> (raw)

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').

Not sure how to fix properly. Metafication/tokenisation stuff is still pretty
confusing to me.

dana



                 reply	other threads:[~2018-01-12 21:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8FFCB628-DDE5-4FE7-B879-A6B4366B896E@dana.is \
    --to=dana@dana.is \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).