Merge pull request #27 from ygurov/hotfix/leading-whitespace-in-value
Some checks are pending
Linux / Build for Ubuntu (push) Waiting to run
Linux / Build for Alpine (push) Waiting to run
Linux / GitHub Release (push) Blocked by required conditions
Windows / Build for Windows (push) Waiting to run
Windows / GitHub Release (push) Blocked by required conditions

fix: revert changes of whitespaces handling
This commit is contained in:
pokamest 2025-07-05 12:41:46 +01:00 committed by GitHub
commit 5877b9b057
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -677,9 +677,6 @@ bool config_read_line(struct config_ctx *ctx, const char *input)
size_t len, cleaned_len = 0;
char *line, *comment;
bool ret = true;
bool found_equals = false;
bool found_value_start = false;
size_t value_end = 0;
/* This is what strchrnul is for, but that isn't portable. */
comment = strchr(input, COMMENT_CHAR);
@ -695,35 +692,9 @@ bool config_read_line(struct config_ctx *ctx, const char *input)
goto out;
}
/* Remove preceding and trailing whitespaces before value
First pass: find the actual end of the value (trim trailing spaces) */
for (size_t i = len; i > 0; --i) {
if (!char_is_space(input[i - 1])) {
value_end = i;
break;
}
}
/* Second pass: clean according to KEY = VALUE rules */
for (size_t i = 0; i < value_end; ++i) {
if (!found_equals) {
/* Before '=': remove all whitespace */
if (input[i] == '=') {
line[cleaned_len++] = input[i];
found_equals = true;
} else if (!char_is_space(input[i])) {
line[cleaned_len++] = input[i];
}
} else if (!found_value_start) {
/* After '=' but before value: skip whitespace until first non-space */
if (!char_is_space(input[i])) {
line[cleaned_len++] = input[i];
found_value_start = true;
}
} else {
/* Within value: preserve all characters including spaces */
for (size_t i = 0; i < len; ++i) {
if (!char_is_space(input[i]))
line[cleaned_len++] = input[i];
}
}
if (!cleaned_len)