Skip to content

Implement proper quote handling for PostgreSQL connection strings#15

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-quote-handling-postgres-connection
Draft

Implement proper quote handling for PostgreSQL connection strings#15
Copilot wants to merge 5 commits intomainfrom
copilot/fix-quote-handling-postgres-connection

Conversation

Copy link
Contributor

Copilot AI commented Nov 1, 2025

The custom connection string parser did not handle quoted values, breaking passwords with spaces or special characters.

Changes

  • Implement custom parser with quote support: Creates an implementation-agnostic parser that handles quoted values, escaped characters, and all sqlpp23 connection_config parameters without using PostgreSQL-specific types
  • Maintain sqlpp23 abstraction: Uses only sqlpp23's connection_config interface, preserving the implementation-agnostic design principle
  • Implement PostgreSQL-compliant boolean parsing: Accepts true/false, on/off, yes/no, 1/0 (case-insensitive)
  • Improve error reporting: Specific messages for invalid values with parameter context

Example

Before:

// This would fail to parse correctly
db = Database("password=my pass word");  // Broken: treats "my" as password

After:

// Now handles quoted values properly
db = Database("password='my pass word'");
db = Database("dbname='test-db' password='p@ss w0rd!'");

Documentation

Updated docs/README.md with connection string format reference and examples showing proper quoting.

Design Note

The implementation uses a custom parser rather than libpq's PQconninfoParse() to maintain the implementation-agnostic interface provided by sqlpp23. This ensures the codebase doesn't become tightly coupled to PostgreSQL-specific types while still providing full quote handling support.

[!WARNING]

Original prompt

This section details on the original issue you should resolve

<filter_complete></filter_complete>

<issue_title>Implement proper quote handling for full PostgreSQL connection string support</issue_title>
<issue_description>See Database.cpp:

        // Parse connection string (PostgreSQL libpq format)
        // Supported format: "key1=value1 key2=value2 ..."
        // Supported keys: host, dbname, user, password, port
        // 
        // NOTE: This parser does not handle quoted values (e.g., password='my pass').
        // Values containing spaces or special characters will be incorrectly parsed.
        // This limitation is acceptable for the keys currently parsed (host, dbname, 
        // user, password, port) as spaces are unlikely to appear in these values.
        // TODO: Create GitHub issue to implement proper quote handling for full 
        // PostgreSQL connection string support (see libpq documentation).
```</issue_description>

<agent_instructions>The quoted lines were from before the introduction of sqlpp23 in this code base. Assess if the quote handling is still needed or if this is already done by sqlpp23.</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

Original prompt

This section details on the original issue you should resolve

<issue_title>Implement proper quote handling for full PostgreSQL connection string support</issue_title>
<issue_description>See Database.cpp:

        // Parse connection string (PostgreSQL libpq format)
        // Supported format: "key1=value1 key2=value2 ..."
        // Supported keys: host, dbname, user, password, port
        // 
        // NOTE: This parser does not handle quoted values (e.g., password='my pass').
        // Values containing spaces or special characters will be incorrectly parsed.
        // This limitation is acceptable for the keys currently parsed (host, dbname, 
        // user, password, port) as spaces are unlikely to appear in these values.
        // TODO: Create GitHub issue to implement proper quote handling for full 
        // PostgreSQL connection string support (see libpq documentation).
```</issue_description>

<agent_instructions>The quoted lines were from before the introduction of sqlpp23 in this code base. Assess if the quote handling is still needed or if this is already done by sqlpp23.</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits November 1, 2025 20:52
Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com>
Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com>
Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement proper quote handling for PostgreSQL connection strings Use libpq's PQconninfoParse for PostgreSQL connection string parsing Nov 1, 2025
Copilot AI requested a review from wdconinc November 1, 2025 20:59
Copy link
Member

@wdconinc wdconinc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot The changes to Database.cpp tie the interface much too close to postgresql. We use sqlpp23 to have an intermediate, implementation-agnostic interface. Using PQconinfoOption violates this benefit. Re-assess this and find a solution for input validation and quoting that maintains the implementation-agnostic sqlpp23 interface.

Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 1, 2025

@copilot The changes to Database.cpp tie the interface much too close to postgresql. We use sqlpp23 to have an intermediate, implementation-agnostic interface. Using PQconinfoOption violates this be...

Reverted the PostgreSQL-specific implementation and replaced it with a custom parser that maintains the implementation-agnostic sqlpp23 interface. The new implementation properly handles quoted values and escaped characters without using PQconninfoOption or any PostgreSQL-specific types. Commit: e7dd942

Copilot AI changed the title Use libpq's PQconninfoParse for PostgreSQL connection string parsing Implement proper quote handling for PostgreSQL connection strings Nov 1, 2025
Copilot AI requested a review from wdconinc November 1, 2025 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement proper quote handling for full PostgreSQL connection string support

2 participants