July 12th, 2024 17:55 UTC · 5 months ago

ShellRust

shell-quote 0.7 is out

Better UTF-8 support, more tests, many fixes, and performance improvements

shell-quote (or on lib.rs):

… escapes strings in a way that they can be inserted into shell scripts without the risk that they’re interpreted as, say, multiple arguments (like with Bash’s word splitting), paths (Bash’s pathname expansion), shell metacharacters, function calls, or other syntax. This is frequently not as simple as wrapping a string in quotes.

That last sentence is echoing around my skull. A lot of work went into this release:

  • There are significant fixes to quoting for /bin/sh1 especially. I strongly encourage upgrading from shell-quote releases prior to 0.7.
  • UTF-8 support has been improved. It was always possible to quote UTF-8 strings, but sequences for code points U+0080 and above would be treated as extended ASCII and escaped as such. Now those code points are encoded directly as UTF-8 sequences.
  • There are more tests, including for UTF-8 support, and more roundtrip tests through the shells themselves. Highlights:
    • Full roundtrips through Dash, Bash, and Z Shell with the Sh quoter.
    • Full roundtrips through Bash and Z Shell with the Bash quoter.
    • UTF-8 tests discovered a (known upstream) bug in fish prior to 3.6.2.
  • Performance has been improved, mainly by removing a couple of optimisations around pre-calculating the size of the output buffer. This also simplifies the code.
  • Features. All shell quoters are enabled by default, as is bstr support, but these can be disabled/enabled in any combination.
  • Lots of documentation improvements.

Upgrading from 0.6.x may require changes in your code, but not many. For example, the Quoter trait is gone, replaced by Quote and QuoteInto. It’s likely that you were not using or implementing Quoter in 0.6.x anyway.

I hope shell-quote is useful to you. Please report bugs if you find them. I do read bug reports – and I usually fix things.

Lastly, thank you to Levi Zim for adding fish support (in 0.6, but I didn’t announce it) and to Mick van Gelderen for suggestions and discussion that make this release better than it would have been otherwise.

1

/bin/sh on most but not all systems is usually Dash these days.