Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitedb5143

Browse files
committed
Fix EXPLAIN so that it doesn't emit invalid XML in corner cases.
With track_io_timing = on, EXPLAIN (ANALYZE, BUFFERS) will emit fieldsnamed like "I/O Read Time". The slash makes that invalid as an XMLelement name, so that adding FORMAT XML would produce invalid XML.We already have code in there to translate spaces to dashes, so let'sgeneralize that to convert anything that isn't a valid XML name character,viz letters, digits, hyphens, underscores, and periods. We could justreject slashes, which would run a bit faster. But the fact that this wentunnoticed for so long doesn't give me a warm feeling that we'd notice thenext creative violation, so let's make it a permanent fix.Reported by Markus Winand, though this isn't his initial patch proposal.Back-patch to 9.2 where track_io_timing was added. The problem is onlylatent in 9.1, so I don't feel a need to fix it there.Discussion: <E0BF6A45-68E8-45E6-918F-741FB332C6BB@winand.at>
1 parent92da752 commitedb5143

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

‎src/backend/commands/explain.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,21 +2552,23 @@ ExplainSeparatePlans(ExplainState *es)
25522552
* Optionally, OR in X_NOWHITESPACE to suppress the whitespace we'd normally
25532553
* add.
25542554
*
2555-
* XML tag names can't contain white space, so we replace any spaces in
2556-
* "tagname" with dashes.
2555+
* XML restricts tag names more than our other output formats, eg they can't
2556+
* contain white space or slashes. Replace invalid characters with dashes,
2557+
* so that for example "I/O Read Time" becomes "I-O-Read-Time".
25572558
*/
25582559
staticvoid
25592560
ExplainXMLTag(constchar*tagname,intflags,ExplainState*es)
25602561
{
25612562
constchar*s;
2563+
constchar*valid="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
25622564

25632565
if ((flags&X_NOWHITESPACE)==0)
25642566
appendStringInfoSpaces(es->str,2*es->indent);
25652567
appendStringInfoCharMacro(es->str,'<');
25662568
if ((flags&X_CLOSING)!=0)
25672569
appendStringInfoCharMacro(es->str,'/');
25682570
for (s=tagname;*s;s++)
2569-
appendStringInfoCharMacro(es->str,(*s==' ') ?'-' :*s);
2571+
appendStringInfoChar(es->str,strchr(valid,*s) ?*s :'-');
25702572
if ((flags&X_CLOSE_IMMEDIATE)!=0)
25712573
appendStringInfoString(es->str," /");
25722574
appendStringInfoCharMacro(es->str,'>');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp