pgconn: fix parseKeywordValueSettings rejecting trailing whitespace#2532
Merged
Conversation
The key-value connection string parser failed with "invalid keyword/value" whenever the string ended with more than one space, or when a quoted value was followed by any trailing spaces. This is because after consuming each value the code only stripped a single byte (s[end+1:]), leaving extra leading whitespace that caused the next loop iteration to see a partial string without an '=' character. Fix by trimming all leading whitespace from the remainder of the string after consuming each value (unquoted and quoted), and also trimming the string once before entering the loop. This matches libpq's behaviour, which accepts any amount of whitespace between and after key-value pairs. Fixes jackc#2284 Signed-off-by: alliasgher <alliasgher123@gmail.com>
Owner
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2284.
parseKeywordValueSettingsrejected valid keyword/value connection strings that had trailing whitespace or multiple spaces between values.Root cause
After consuming each value, the parser advanced by one byte (
s[end+1:]for unquoted values,s[end+1:]after the closing quote for quoted values). This skipped a single whitespace character but left any additional leading spaces ins. On the next iteration, the loop found no=in" "and returned"invalid keyword/value".The same issue occurred with quoted values followed by any trailing whitespace, because
s[end+1:]only moved past the closing'and left the spaces.Fix
sonce before entering the loop so that an entirely-whitespace input exits cleanly.strings.TrimLeft(…)instead of[end+1:]to consume all subsequent whitespace. This matcheslibpq's behavior and the PostgreSQL documentation, which describes the connection string syntax as allowing spaces between key-value pairs.Tests added
TestParseConfigKVTrailingWhitespacecovers: