Meson: Dollar literals aren't escaped

Created on 24 Mar 2017  路  14Comments  路  Source: mesonbuild/meson

Ninja uses $ as an escape character, but commands can include literal '$' characters, so these should be escaped as well.

For instance, the following:

perl = find_program('perl')
run_target('t', command : [perl, '-e', 'my $v = "Hello World"; print($v)'])

currently yields:

'/usr/bin/perl' '-e' 'my$ $v$ =$ "Hello$ World";$ print($v)'

instead of

'/usr/bin/perl' '-e' 'my$ $$v$ =$ "Hello$ World";$ print($$v)'
bug

Most helpful comment

All 14 comments

I could have sworn there was a PR that did this, but I can't find it...

It is very, _very_ highly recommended that you do _not_ try to pass shell pipelines through any sort of command line. It will break in a dozen different ways and you will hate your life. Write your functionality in a standalone script and run that. This is more readable and you can test your functionality by running it from the command line directly.

@jpakkane Sure thing, wasn't planning on writing whole scripts inline ;)

However, for extremely simple stuff like writing an array of strings/files to a file in a portable manner, one liners can be nice to have.

In any case, '$' can potentially appear as an argument to scripts, so this issue may be hit regardless.

$ can also appear in regular expressions, so that's another reason to fix this. I already hit this once and had to make a wrapper Python script.

Note that anything that has dollar signs on the command line is inherently not portable. It means trying to invoke (usually) shell, Perl or Sed. None of these is portable because Windows cmd.exe does not have them.

@jpakkane Some projects use perl even on Windows, and not sure it's less portable than, say, python ;)

..though granted, python is surely installed on a system running meson to begin with.

Because Python 3 is guaranteed to be available as Meson is implemented in it.

@jpakkane Right, but projects using meson aren't necessarily required to use python3 as part of their build, especially when some developers prefer other scripting languages ;)

In any case, @nirbheek's comment also holds for python.

None of this matters because even filenames can have $ in them, especially on Windows. For example: $Recycle.Bin (that's the recycle bin folder, yes). It's also a pretty easy substitution anyway, right? Just replace all $ with $$ without thinking. There are no exceptions afaict.

@nirbheek Certainly seems that way, yes.

Aha, I knew I saw it somewhere!

Is this now fixed by the mentioned commit?

Not that commit specifically, but a version of it, I'd think so.

Was this page helpful?
0 / 5 - 0 ratings