Skip to content

Match SplitGUCList semantics when parsing output_plugin_libraries - #8797

Merged
ibrahim halatci (ihalatci) merged 1 commit into
release-13.2from
fix-output-plugin-parse-release-13.2
Aug 26, 2026
Merged

ibrahim halatci (ihalatci) merged 1 commit into
release-13.2from
fix-output-plugin-parse-release-13.2

Conversation

@ihalatci

Copy link
Copy Markdown
Contributor

DESCRIPTION: Match SplitGUCList semantics parsing output_plugin_libraries

Backport of the SQL tightening from #8777, addressing Onur Tirtir (@onurctirtir)'s review
comment there.

What was wrong

ErrorIfOutputPluginNotAllowed() parsed output_plugin_libraries with
btrim(name, ' "'), which strips spaces and double quotes from either end in
any combination. PostgreSQL's real parser is SplitGUCList (guc.c), which:

  • splits on commas,
  • trims all whitespace (space, \t, \n, \r, \f) from each element,
  • removes the surrounding quotes only when an element is fully quoted,
    collapsing interior "" to " and preserving interior whitespace.

The two disagreed in both directions:

output_plugin_libraries PostgreSQL old SQL consequence
" citus " citus -> no match citus -> match false positive: preflight passes, the split fails later anyway
pgoutput,<TAB>citus citus -> match <TAB>citus -> no match false negative: we block a split PostgreSQL would have allowed

current_setting() does not normalize the tab away, so the false negative is
reachable.

The fix

Trim E' \t\n\r\f' per element, then unwrap a fully-quoted element and
collapse doubled inner quotes -- i.e. exactly what SplitGUCList does.

coalesce(bool_or(CASE WHEN name LIKE '"%"' THEN
  replace(substring(name, 2, length(name) - 2), '""', '"')
  ELSE name END = 'citus'), false)
FROM (SELECT btrim(elem, E' \t\n\r\f') AS name
      FROM unnest(string_to_array(coalesce(
        current_setting('output_plugin_libraries', true), 'citus'), ',')) elem) s

Note \v is deliberately excluded: scanner_isspace does not treat it as
whitespace, so a POSIX [[:space:]] class would over-trim.

Verification

The expression was extracted straight out of the compiled appendStringInfo
format string and run against PostgreSQL 16.15, using
pg_create_logical_replication_slot as ground truth. All probed cases agree,
including tab and newline separators, quoted elements with interior spaces, and
doubled inner quotes.

Known, deliberate limitation

A comma inside a quoted element ("a,b") still splits incorrectly, because
string_to_array is comma-blind. Unreachable for the name citus; left alone
to keep the change minimal.

Co-authored-by: Copilot App [email protected]

The preflight check used btrim(name, ' "'), which strips spaces and
double quotes from either end in any combination. PostgreSQL's real
parser (SplitGUCList) instead trims all whitespace, then removes the
surrounding quotes only when an element is fully quoted, collapsing
interior "" to ".

The two parsers therefore disagreed in both directions:

  '" citus "'    PG sees ` citus ` (no match) - we saw a match, so the
                 preflight passed and the split failed later anyway.
  'pgoutput,\tcitus'
                 PG sees `citus` (match) - we saw `\tcitus`, so we
                 blocked a split PostgreSQL would have allowed.
                 current_setting() does not normalize the tab away.

Verified against PostgreSQL 16.15 using
pg_create_logical_replication_slot as ground truth: the new expression
agrees with the server in all probed cases, including tab/newline
separators and doubled inner quotes.

Backport of the fix in #8777, addressing review feedback from
@onurctirtir.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 7c6370b2-06fd-4491-bf92-ecb811d34518
@ihalatci
ibrahim halatci (ihalatci) merged commit 5fe77a9 into release-13.2 Aug 26, 2026
181 of 213 checks passed
@ihalatci
ibrahim halatci (ihalatci) deleted the fix-output-plugin-parse-release-13.2 branch August 26, 2026 09:12
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.

1 participant