The pg_amcheck reports a skip message if the layout of the index does not match expectations. That message includes the bytes that were expected and the ones that were found. But the found ones are arbitrary bytes, which can have funny effects on the terminal when they are printed. To avoid that, escape non-word characters before printing.
From 09d82d19e045114b1e2e7c3751e96cbae1eaaa0c Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Mon, 8 Jan 2024 08:23:26 +0100
Subject: [PATCH] Escape output of pg_amcheck test

The pg_amcheck reports a skip message if the layout of the index does
not match expectations.  That message includes the bytes that were
expected and the ones that were found.  But the found ones are
arbitrary bytes, which can have funny effects on the terminal when
they are printed.  To avoid that, escape non-word characters before
printing.
---
 src/bin/pg_amcheck/t/004_verify_heapam.pl | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/bin/pg_amcheck/t/004_verify_heapam.pl 
b/src/bin/pg_amcheck/t/004_verify_heapam.pl
index 8c796ed221..f6d2c5f787 100644
--- a/src/bin/pg_amcheck/t/004_verify_heapam.pl
+++ b/src/bin/pg_amcheck/t/004_verify_heapam.pl
@@ -367,10 +367,11 @@ sub write_tuple
        {
                close($file);    # ignore errors on close; we're exiting anyway
                $node->clean_node;
-               plan skip_all =>
-                 sprintf(
+               plan skip_all => sprintf(
                        "Page layout of index %d differs from our expectations: 
expected (%x, %x, \"%s\"), got (%x, %x, \"%s\")",
-                       $tupidx, 0xDEADF9F9, 0xDEADF9F9, "abcdefg", $a_1, $a_2, 
$b);
+                       $tupidx, 0xDEADF9F9, 0xDEADF9F9, "abcdefg", $a_1, $a_2,
+                       # escape non-word characters to avoid confusing the 
terminal
+                       $b =~ s{(\W)}{ sprintf '\x%02x', ord($1) }aegr);
                exit;
        }
 
-- 
2.43.0

Reply via email to