From 60f6db1c8aad95d517a09c63a1beef261433e825 Mon Sep 17 00:00:00 2001 From: Nathan Schulte Date: Mon, 24 Jul 2023 11:37:38 -0500 Subject: [PATCH] Support quoted INI string values support singly and doubly quoted INI strings, for e.g. leading and trailing spaces in WiFi SSID/PSK field values --- lib/inih/ini.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/inih/ini.c b/lib/inih/ini.c index b4d5921211..111b6bea92 100644 --- a/lib/inih/ini.c +++ b/lib/inih/ini.c @@ -51,6 +51,18 @@ static char* lskip(const char* s) return (char*)s; } +/* Strip quotes from single and double quoted strings */ +static char* unquote(char* s) +{ + int l = strlen(s); + if (l && s[0] == s[l - 1] && (s[0] == '\'' || s[0] == '"')) + { + s[l - 1] = '\0'; + s++; + } + return s; +} + /* Return pointer to first char (of chars) or inline comment in given string, or pointer to null at end of string if neither found. Inline comment must be prefixed by a whitespace character to register as a comment. */ @@ -194,6 +206,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, #endif value = lskip(value); rstrip(value); + unquote(value); /* Valid name[=:]value pair found, call handler */ strncpy0(prev_name, name, sizeof(prev_name));