New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add str.to_quoted #10417
Comments
It would do python's |
AFAIK, Meson will already shell quote every args it pass to the compiler for you. Have you tried and it does not work? |
Yeah. Same as
Nah, this won't work, the value needs to be quoted as well for the C parser to recognize it as a C string and not another kind of literal. Example: project('test', 'c')
myvar = 'a b " c'
add_project_arguments('-DMYVAR=' + myvar, language: 'c')
executable('main', 'main.c') #include <stdio.h>
int main(void) {
printf("MYVAR = %s\n", MYVAR);
} |
Configuration data uses C-style escaping, and the specific implementation details are:
This is not what shlex does at all, because shells use different rules that need to account for pretty different things. Particularly worth noting is that shlex will not quote at all, if it is given a string that doesn't have any whitespace/quoting/shell special characters, e.g.
|
As a general guide, try to avoid passing things via command line arguments. They are a constant source of trouble even when things are working. It is a lot easier to use a configuration header instead. Just the fact that you can debug its contents without needing to manually unwrap several layers of different quotings makes things so much simpler. |
I would tend to agree, at least when |
Ok, so here we talk about C string level quoting, not shlex, wasn't sure. Makes much more sense. |
ninja runs in a shell, and meson writes out shell-escaped command lines. So there are two levels of quoting:
Plus whatever any unusual individual chooses to add in the string, because someone out there is totally going to do 'ab$\'c d"""!e'.to_quoted() And expect it to work. They're also probably going to expect it to work regardless of whether it's being stuck in a c_args or formatted into Spoiler: it won't work for both. :( |
Oh. I didn't know ninja was dealing with sh. That's unfortunate. Indeed, shell quoting doesn't work like C quoting. Would a function named Or something like |
Allow adding quotes to a string with a new
str.to_quoted
method. This would be useful for things like:which would behave properly even if
arbitrary_string
contains a"
or a\
.The text was updated successfully, but these errors were encountered: