mirror of
https://gitlab.freedesktop.org/pkg-config/pkg-config.git
synced 2025-12-20 03:10:03 +01:00
Only unquote --variable when it appears quoted
The change to unquote values in the --variable output broke users that had shell special characters in the variable. Instead, only unquote if the value starts with " or '. A larger fix to do a full unquote, split and escaping like --cflags/--libs is possible, but that might break the old semantics even further. Add a new function, parse_package_variable(), to handle that logic. https://bugs.freedesktop.org/show_bug.cgi?id=93284
This commit is contained in:
parent
e6d33fb129
commit
1c564a3583
3 changed files with 46 additions and 15 deletions
36
parse.c
36
parse.c
|
|
@ -1145,3 +1145,39 @@ parse_package_file (const char *key, const char *path,
|
|||
|
||||
return pkg;
|
||||
}
|
||||
|
||||
/* Parse a package variable. When the value appears to be quoted,
|
||||
* unquote it so it can be more easily used in a shell. Otherwise,
|
||||
* return the raw value.
|
||||
*/
|
||||
char *
|
||||
parse_package_variable (Package *pkg, const char *variable)
|
||||
{
|
||||
char *value;
|
||||
char *unquoted;
|
||||
GError *error = NULL;
|
||||
|
||||
value = package_get_var (pkg, variable);
|
||||
if (!value)
|
||||
return NULL;
|
||||
|
||||
if (*value != '"' && *value != '\'')
|
||||
/* Not quoted, return raw value */
|
||||
return value;
|
||||
|
||||
/* Maybe too naive, but assume a fully quoted variable */
|
||||
unquoted = g_shell_unquote (value, &error);
|
||||
if (unquoted)
|
||||
{
|
||||
g_free (value);
|
||||
return unquoted;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Note the issue, but just return the raw value */
|
||||
debug_spew ("Couldn't unquote value of \"%s\": %s\n",
|
||||
variable, error ? error->message : "unknown");
|
||||
g_clear_error (&error);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
parse.h
2
parse.h
|
|
@ -29,6 +29,8 @@ Package *parse_package_file (const char *key, const char *path,
|
|||
|
||||
GList *parse_module_list (Package *pkg, const char *str, const char *path);
|
||||
|
||||
char *parse_package_variable (Package *pkg, const char *variable);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
23
pkg.c
23
pkg.c
|
|
@ -1070,40 +1070,33 @@ package_get_var (Package *pkg,
|
|||
}
|
||||
|
||||
char *
|
||||
packages_get_var (GList *pkgs,
|
||||
packages_get_var (GList *pkgs,
|
||||
const char *varname)
|
||||
{
|
||||
GList *tmp;
|
||||
GString *str;
|
||||
char *retval;
|
||||
|
||||
str = g_string_new ("");
|
||||
|
||||
|
||||
str = g_string_new (NULL);
|
||||
|
||||
tmp = pkgs;
|
||||
while (tmp != NULL)
|
||||
{
|
||||
Package *pkg = tmp->data;
|
||||
char *var;
|
||||
|
||||
var = package_get_var (pkg, varname);
|
||||
|
||||
var = parse_package_variable (pkg, varname);
|
||||
if (var)
|
||||
{
|
||||
if (str->len > 0)
|
||||
g_string_append_c (str, ' ');
|
||||
g_string_append (str, var);
|
||||
g_string_append_c (str, ' ');
|
||||
g_free (var);
|
||||
}
|
||||
|
||||
tmp = g_list_next (tmp);
|
||||
}
|
||||
|
||||
/* chop last space */
|
||||
if (str->len > 0)
|
||||
str->str[str->len - 1] = '\0';
|
||||
retval = str->str;
|
||||
g_string_free (str, FALSE);
|
||||
|
||||
return retval;
|
||||
return g_string_free (str, FALSE);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue