Ticket #38728

tilde expansion active in quoted parameter substitution

Open Date: 2018-11-06 05:48 Last Update: 2018-11-26 00:19

Reporter:
Owner:
Type:
Status:
Open [Owner assigned]
Component:
MileStone:
(None)
Priority:
3
Severity:
5 - Medium
Resolution:
Postponed
File:
1
Vote
Score: 0
No votes
0.0% (0/0)
0.0% (0/0)

Details

Quoting should deactivate tilde expansion, but yash still expands tildes in quoted parameter expansions.

$ yash -c 'unset foo; echo "${foo:-~/test}"'
/Users/martijn/test

Expected output: ~/test (as per dash, bash, *ksh, zsh)

Ticket History (3/6 Histories)

2018-11-06 05:48 Updated by: mcdutchie
  • New Ticket "tilde expansion active in quoted parameter substitution" created
2018-11-07 23:30 Updated by: magicant
Comment

Thanks for reporting.

Looks like this is the same kind of issue as #36278. POSIX does not precisely define how double-quotes modify interpretation of other special characters.

2018-11-25 17:01 Updated by: magicant
Comment

The behavior of other shells is consistent for "${unset-~}", "${unset+~}", and "${unset=~}", but for "${unset?~}"...

+ bash -o posix -c 'echo ${unset?~}'
bash: unset: /home/magicant
+ bash -o posix -c 'echo "${unset?~}"'
bash: unset: /home/magicant
+ ksh -c 'echo ${unset?~}'
ksh: unset: /home/magicant
+ ksh -c 'echo "${unset?~}"'
ksh: unset: ~
+ mksh -o posix -c 'echo ${unset?~}'
mksh: unset: /home/magicant
+ mksh -o posix -c 'echo "${unset?~}"'
mksh: unset: ~
+ zsh --emulate sh -c 'echo ${unset?~}'
zsh:1: unset: ~
+ zsh --emulate sh -c 'echo "${unset?~}"'
zsh:1: unset: ~
2018-11-25 23:23 Updated by: magicant
Comment

Korn shell is quite strange in that tilde expansion is enabled in "${foo#~}" but not in "${foo##~}".

2018-11-26 00:19 Updated by: magicant
  • Priority Update from 5 - Medium to 3
  • Component Update from (None) to shell-main
  • Resolution Update from None to Postponed
  • Owner Update from (None) to magicant
Comment

The attached patch should fix this.

On second thought, however, I'm in doubt whether this should be really "fixed." POSIX explicitly says, "In each case that a value of word is needed (based on the state of parameter, ...), word shall be subjected to tilde expansion, parameter expansion, command substitution, and arithmetic expansion." (XCU 2.6.2) POSIX does not explicitly require tilde expansion be disabled in quoted expansion. Then what interpretation of POSIX can deny the current behavior of yash?

I'm postponing this, maybe until POSIX is revised for clarity.

Edit

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Login