From fb49e437c6482992b6a2ab76fab48987b601d2be Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Thu, 19 Nov 2026 01:08:57 -0700 Subject: [PATCH 1/4] Test that array elements keep non-ASCII edge whitespace PostgreSQL quotes an array element only when it contains ASCII whitespace, so an element that starts or ends with a no-break space or another Unicode space separator arrives unquoted. This test reads such elements untyped and through a typed Vector{String} field. Co-Authored-By: Claude Opus 5.5 --- test/runtests.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index f3c5bb7..ec8a4c5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1371,7 +1371,14 @@ include("trim_compile_tests.jl") bracket_param = ["a]b", "x[1]", "]", "plain"] bracket_row = only(Tables.rowtable(DBInterface.execute(conn, raw"SELECT $1::text[] AS arr", (bracket_param,)))) @test bracket_row.arr == bracket_param - array_row = only(Tables.rowtable(DBInterface.execute(conn, "SELECT '{1,NULL,3}'::int[] AS arr"))) + # PostgreSQL quotes an element only for ASCII whitespace, so + # other whitespace at an element's edge arrives unquoted + edge_ws = [" lead", "trail ", "
both ", "a b"] + edge_row = only(Tables.rowtable(DBInterface.execute(conn, + raw"SELECT ARRAY[E' lead', E'trail ', E'
both ', 'a b'] AS arr"))) + @test edge_row.arr == edge_ws + @test DBInterface.execute(conn, raw"SELECT $1::text[] AS arr", (edge_ws,), NamedTuple{(:arr,), Tuple{Vector{String}}}).arr == edge_ws + array_row =only(Tables.rowtable(DBInterface.execute(conn, "SELECT '{1,NULL,3}'::int[] AS arr"))) @test isequal(array_row.arr, Union{Missing, Int32}[1, missing, 3]) nested_row = only(Tables.rowtable(DBInterface.execute(conn, "SELECT '{{1,2},{3,4}}'::int[] AS arr"))) @test nested_row.arr == [Int32[1, 2], Int32[3, 4]] From eaea5ce6cdbd07aeca35c325ba44d4181788cca9 Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Thu, 19 Nov 2026 01:10:48 -0700 Subject: [PATCH 2/4] Keep non-ASCII edge whitespace in unquoted array elements PostgreSQL's array output quotes an element only when it contains ASCII whitespace, so an element that starts or ends with U+00A0 (no-break space), U+3000, or another Unicode space separator arrives unquoted. parse_unquoted trimmed elements with Base.strip, which also removes those characters, so they were silently dropped from decoded text, varchar, and char arrays, untyped and typed alike. Trim only the ASCII whitespace the array grammar itself ignores. Co-Authored-By: Claude Opus 5.5 --- src/array_parsing.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/array_parsing.jl b/src/array_parsing.jl index 919356f..326402f 100644 --- a/src/array_parsing.jl +++ b/src/array_parsing.jl @@ -70,7 +70,13 @@ function parse_unquoted(code::Base.CodeUnits{UInt8, String}, pos::Ref{Int}) pos[] += 1 end end - return String(strip(String(buf))) + # Trim only the ASCII whitespace PostgreSQL itself ignores around an + # element. Base.strip also removes Unicode spaces such as U+00A0, which + # the server never quotes, so they belong to the element. + while !isempty(buf) && is_ws(buf[end]) + pop!(buf) + end + return String(buf) end function parse_bool_token(token::String) From fd1133597ac1d0945a5e762d90021b31b0d141cf Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Thu, 19 Nov 2026 01:29:09 -0700 Subject: [PATCH 3/4] Do not trim unquoted array elements at all The server quotes every element that contains ASCII whitespace, so the trailing-whitespace trim could only run on text the server never sends. Co-Authored-By: Claude Opus 5.5 --- src/array_parsing.jl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/array_parsing.jl b/src/array_parsing.jl index 326402f..eabde12 100644 --- a/src/array_parsing.jl +++ b/src/array_parsing.jl @@ -70,12 +70,9 @@ function parse_unquoted(code::Base.CodeUnits{UInt8, String}, pos::Ref{Int}) pos[] += 1 end end - # Trim only the ASCII whitespace PostgreSQL itself ignores around an - # element. Base.strip also removes Unicode spaces such as U+00A0, which - # the server never quotes, so they belong to the element. - while !isempty(buf) && is_ws(buf[end]) - pop!(buf) - end + # The server quotes any element that contains ASCII whitespace, so an + # unquoted element runs to the delimiter. Unicode spaces such as U+00A0 + # are never quoted and belong to the element: do not strip. return String(buf) end From 41b0fce52897193cbe9da6f14094a8447fb61b50 Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Thu, 19 Nov 2026 01:38:38 -0700 Subject: [PATCH 4/4] Spell the test's Unicode spaces as escapes Co-Authored-By: Claude Opus 5.5 --- test/runtests.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index ec8a4c5..4c99992 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1373,12 +1373,12 @@ include("trim_compile_tests.jl") @test bracket_row.arr == bracket_param # PostgreSQL quotes an element only for ASCII whitespace, so # other whitespace at an element's edge arrives unquoted - edge_ws = [" lead", "trail ", "
both ", "a b"] + edge_ws = ["\u00a0lead", "trail\u00a0", "\u2028both\u3000", "a b"] edge_row = only(Tables.rowtable(DBInterface.execute(conn, - raw"SELECT ARRAY[E' lead', E'trail ', E'
both ', 'a b'] AS arr"))) + raw"SELECT ARRAY[E'\u00a0lead', E'trail\u00a0', E'\u2028both\u3000', 'a b'] AS arr"))) @test edge_row.arr == edge_ws @test DBInterface.execute(conn, raw"SELECT $1::text[] AS arr", (edge_ws,), NamedTuple{(:arr,), Tuple{Vector{String}}}).arr == edge_ws - array_row =only(Tables.rowtable(DBInterface.execute(conn, "SELECT '{1,NULL,3}'::int[] AS arr"))) + array_row = only(Tables.rowtable(DBInterface.execute(conn, "SELECT '{1,NULL,3}'::int[] AS arr"))) @test isequal(array_row.arr, Union{Missing, Int32}[1, missing, 3]) nested_row = only(Tables.rowtable(DBInterface.execute(conn, "SELECT '{{1,2},{3,4}}'::int[] AS arr"))) @test nested_row.arr == [Int32[1, 2], Int32[3, 4]]