diff options
| author | Tom Lane | 2018-04-17 23:53:50 +0000 |
|---|---|---|
| committer | Tom Lane | 2018-04-17 23:53:50 +0000 |
| commit | 55d26ff638f063fbccf57843f2c27f9795895a5c (patch) | |
| tree | bb094186f374620288b702217f8c26280dc9f719 /src/backend | |
| parent | 9ffcccdb958d38db5051bf64143330ff445a26cc (diff) | |
Rationalize handling of single and double quotes in bootstrap data.
Change things around so that proper quoting of values interpolated into
the BKI data by initdb is the responsibility of initdb, not something
we half-heartedly handle by putting double quotes into the raw BKI data.
(Note: experimentation shows that it still doesn't work to put a double
quote into the initial superuser username, but that's the fault of
inadequate quoting while interpolating the name into SQL scripts;
the BKI aspect of it works fine now.)
Having done that, we can remove the special-case handling of values
that look like "something" from genbki.pl, and instead teach it to
escape double --- and single --- quotes properly. This removes the
nowhere-documented need to treat those specially in the BKI source
data; whatever you write will be passed through unchanged into the
inserted data value, modulo Perl's rules about single-quoted strings.
Add documentation explaining the (pre-existing) handling of backslashes
in the BKI data.
Per an earlier discussion with John Naylor.
Discussion: https://postgr.es/m/CAJVSVGUNao=-Q2-vAN3PYcdF5tnL5JAHwGwzZGuYHtq+Mk_9ng@mail.gmail.com
Diffstat (limited to 'src/backend')
| -rw-r--r-- | src/backend/catalog/genbki.pl | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl index b750ec9f0ac..938686f0ca7 100644 --- a/src/backend/catalog/genbki.pl +++ b/src/backend/catalog/genbki.pl @@ -660,12 +660,19 @@ sub print_bki_insert # since that represents a NUL char in C code. $bki_value = '' if $bki_value eq '\0'; + # Handle single quotes by doubling them, and double quotes by + # converting them to octal escapes, because that's what the + # bootstrap scanner requires. We do not process backslashes + # specially; this allows escape-string-style backslash escapes + # to be used in catalog data. + $bki_value =~ s/'/''/g; + $bki_value =~ s/"/\\042/g; + # Quote value if needed. We need not quote values that satisfy # the "id" pattern in bootscanner.l, currently "[-A-Za-z0-9_]+". $bki_value = sprintf(qq'"%s"', $bki_value) - if $bki_value !~ /^"[^"]+"$/ - and ( length($bki_value) == 0 - or $bki_value =~ /[^-A-Za-z0-9_]/); + if length($bki_value) == 0 + or $bki_value =~ /[^-A-Za-z0-9_]/; push @bki_values, $bki_value; } |
