oils-for-unix / oils

Oils is our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!
http://www.oilshell.org/
Other
2.84k stars 157 forks source link

IFS=: and : in literal word gives incorrect results #628

Open xPMo opened 4 years ago

xPMo commented 4 years ago

Input:

IFS=':'; word='a:'
printf '[%s] ' ${word}:b

Bash, Dash, etc:

[a] [:b]

Osh:

[a] [\] [b]

Input:

IFS=':'; word='a:'
printf '[%s] ' ${word}:

Bash, Dash, etc:

[a] [:]

Osh: (crashes, stderr)

Traceback (most recent call last):
  File "/home/pmo/Repos/oil/bin/oil.py", line 962, in <module>
    sys.exit(main(sys.argv))
  [...]
  File "/home/pmo/Repos/oil/osh/glob_.py", line 129, in GlobUnescape
    assert i != n - 1, 'Trailing backslash: %r' % s
AssertionError: Trailing backslash: '\\'
andychu commented 4 years ago

Doh, good catch. Yes it appears this is related to the IFS='\' bug I mentioned on #627 and that's exposed by the spec tests.

This makes fixing that a higher priority (both bugs can be fixed at once), although it's a little hairy and I'm not sure exactly when.

Keep the bug reports coming in any case! I haven't gotten any "fundamental language" bugs in awhile, and it helps to catch them early.

andychu commented 4 years ago

Hm I'm getting the crash in both cases, with ${word}: and ${word}:b. I haven't gotten:

[a] [\] [b]

I'm not sure how important it is, but what version of OSH can you reproduce that with?


In any case I'm pretty sure I know how to fix it, but it's a bit hairy. I have to carry along some booleans further through the word expansion pipeline.

xPMo commented 4 years ago

I can't reproduce it anymore, which is bizarre.