Browse Source

libpkgconf: tuple: tighten quoting logic a bit

closes #12
William Pitcock 11 months ago
parent
commit
662957ca7d
2 changed files with 8 additions and 5 deletions
  1. 2
    0
      NEWS
  2. 6
    5
      libpkgconf/tuple.c

+ 2
- 0
NEWS View File

@@ -12,6 +12,8 @@ Changes from 1.6.0 to 1.6.1:
12 12
     paths.
13 13
   - Use POSIX realpath(3) instead of readlink() for deduplicating the
14 14
     search path.  Use _fullpath() on Windows for the same purpose.
15
+  - The dequoting logic for tuples has been improved to ensure that
16
+    quotes *inside* a value remain quoted when necessary.
15 17
 
16 18
 Changes from 1.5.4 to 1.6.0:
17 19
 ----------------------------

+ 6
- 5
libpkgconf/tuple.c View File

@@ -144,17 +144,18 @@ dequote(const char *value)
144 144
 	const char *i;
145 145
 	char quote = 0;
146 146
 
147
+	if (*value == '\'' || *value == '"')
148
+		quote = *value;
149
+
147 150
 	for (i = value; *i != '\0'; i++)
148 151
 	{
149
-		if (!quote && (*i == '\'' || *i == '"'))
150
-			quote = *i;
151
-		else if (*i != quote)
152
-			*bptr++ = *i;
153
-		else if (*i == '\\' && *(i + 1) == quote)
152
+		if (*i == '\\' && quote && *(i + 1) == quote)
154 153
 		{
155 154
 			i++;
156 155
 			*bptr++ = *i;
157 156
 		}
157
+		else if (*i != quote)
158
+			*bptr++ = *i;
158 159
 	}
159 160
 
160 161
 	return buf;