connection string/url parsing and generation in the server configuration dialog

This commit is contained in:
eelke 2025-08-31 10:12:22 +02:00
parent a5cb6ef7d4
commit 1d53ca2fc2
11 changed files with 410 additions and 62 deletions

View file

@ -16,6 +16,9 @@ public sealed class LibpqCodec : IConnectionStringCodec
{
try
{
// Reject Npgsql-style strings that use ';' separators when forcing libpq
if (input.IndexOf(';') >= 0)
return Result.Fail<ConnectionDescriptor>("Semicolons are not valid separators in libpq connection strings");
var kv = new PqConnectionStringParser(new PqConnectionStringTokenizer(input)).Parse();
// libpq keywords are case-insensitive; normalize to lower for lookup

View file

@ -67,13 +67,29 @@ public class PqConnectionStringTokenizer : IPqConnectionStringTokenizer
{
while (position < input.Length && char.IsWhiteSpace(input[position]))
position++;
// If a semicolon is encountered between pairs (which is not valid in libpq),
// treat as immediate EOF so parser stops and leaves trailing data unparsed.
if (position < input.Length && input[position] == ';')
{
position = input.Length; // force EOF
}
}
private string UnquotedString(bool forKeyword)
{
int start = position;
while (++position < input.Length && !char.IsWhiteSpace(input[position]) && (!forKeyword || input[position] != '='))
{ }
while (++position < input.Length)
{
char c = input[position];
// Libpq syntax does not use semicolons as pair separators; treat ';' as invalid here
if (c == ';')
{
// Force tokenizer to stop and later cause a parse error by making GetValue/keyword incomplete
break;
}
if (char.IsWhiteSpace(c)) break;
if (forKeyword && c == '=') break;
}
return input.Substring(start, position - start);
}