|
7 | 7 | * Portions Copyright (c) 1994-5, Regents of the University of California
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.205 2010/06/09 02:39:34 rhaas Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.206 2010/06/10 01:26:30 rhaas Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -1698,8 +1698,7 @@ ExplainPropertyList(const char *qlabel, List *data, ExplainState *es)
|
1698 | 1698 |
|
1699 | 1699 | case EXPLAIN_FORMAT_YAML:
|
1700 | 1700 | ExplainYAMLLineStarting(es);
|
1701 |
| - escape_yaml(es->str, qlabel); |
1702 |
| - appendStringInfoChar(es->str, ':'); |
| 1701 | + appendStringInfo(es->str, "%s: ", qlabel); |
1703 | 1702 | foreach(lc, data)
|
1704 | 1703 | {
|
1705 | 1704 | appendStringInfoChar(es->str, '\n');
|
@@ -1759,7 +1758,10 @@ ExplainProperty(const char *qlabel, const char *value, bool numeric,
|
1759 | 1758 | case EXPLAIN_FORMAT_YAML:
|
1760 | 1759 | ExplainYAMLLineStarting(es);
|
1761 | 1760 | appendStringInfo(es->str, "%s: ", qlabel);
|
1762 |
| - escape_yaml(es->str, value); |
| 1761 | + if (numeric) |
| 1762 | + appendStringInfoString(es->str, value); |
| 1763 | + else |
| 1764 | + escape_yaml(es->str, value); |
1763 | 1765 | break;
|
1764 | 1766 | }
|
1765 | 1767 | }
|
@@ -1857,8 +1859,7 @@ ExplainOpenGroup(const char *objtype, const char *labelname,
|
1857 | 1859 | ExplainYAMLLineStarting(es);
|
1858 | 1860 | if (labelname)
|
1859 | 1861 | {
|
1860 |
| - escape_yaml(es->str, labelname); |
1861 |
| - appendStringInfoChar(es->str, ':'); |
| 1862 | + appendStringInfo(es->str, "%s: ", labelname); |
1862 | 1863 | es->grouping_stack = lcons_int(1, es->grouping_stack);
|
1863 | 1864 | }
|
1864 | 1865 | else
|
@@ -2152,48 +2153,17 @@ escape_json(StringInfo buf, const char *str)
|
2152 | 2153 | }
|
2153 | 2154 |
|
2154 | 2155 | /*
|
2155 |
| - * YAML is a superset of JSON, so we can use JSON escaping when escaping is |
2156 |
| - * needed. However, some things that need to be quoted in JSON don't require |
2157 |
| - * quoting in YAML, and we prefer not to quote unnecessarily, to improve |
2158 |
| - * readability. |
2159 |
| - * |
2160 |
| - * Unfortunately, the YAML quoting rules are ridiculously complicated -- as |
2161 |
| - * documented in sections 5.3 and 7.3.3 of http://yaml.org/spec/1.2/spec.html |
2162 |
| - * -- and it doesn't seem worth expending a large amount of energy to avoid |
2163 |
| - * all unnecessary quoting, so we just do something (sort of) simple: we quote |
2164 |
| - * any string which is empty; any string which contains characters other than |
2165 |
| - * alphanumerics, period, underscore, or space; or begins or ends with a |
2166 |
| - * space. The exception for period is mostly so that floating-point numbers |
2167 |
| - * (e.g., cost values) won't be quoted. |
| 2156 | + * YAML is a superset of JSON; unfortuantely, the YAML quoting rules are |
| 2157 | + * ridiculously complicated -- as documented in sections 5.3 and 7.3.3 of |
| 2158 | + * http://yaml.org/spec/1.2/spec.html -- so we chose to just quote everything. |
| 2159 | + * Empty strings, strings with leading or trailing whitespace, and strings |
| 2160 | + * containing a variety of special characters must certainly be quoted or the |
| 2161 | + * output is invalid; and other seemingly harmless strings like "0xa" or |
| 2162 | + * "true" must be quoted, lest they be interpreted as a hexadecimal or Boolean |
| 2163 | + * constant rather than a string. |
2168 | 2164 | */
|
2169 | 2165 | static void
|
2170 | 2166 | escape_yaml(StringInfo buf, const char *str)
|
2171 | 2167 | {
|
2172 |
| - bool needs_quoting = false; |
2173 |
| - |
2174 |
| -#define is_safe_yaml(x) \ |
2175 |
| - (isalnum(((unsigned char) x)) || (x) == '.' || (x) == '_') |
2176 |
| - |
2177 |
| - if (!is_safe_yaml(str[0])) |
2178 |
| - needs_quoting = true; |
2179 |
| - else |
2180 |
| - { |
2181 |
| - const char *p; |
2182 |
| - |
2183 |
| - for (p = str; *p; p++) |
2184 |
| - { |
2185 |
| - if (*p != ' ' && !is_safe_yaml(*p)) |
2186 |
| - { |
2187 |
| - needs_quoting = true; |
2188 |
| - break; |
2189 |
| - } |
2190 |
| - } |
2191 |
| - if (!*p && p[-1] == ' ') |
2192 |
| - needs_quoting = true; |
2193 |
| - } |
2194 |
| - |
2195 |
| - if (needs_quoting) |
2196 |
| - escape_json(buf, str); |
2197 |
| - else |
2198 |
| - appendStringInfoString(buf, str); |
| 2168 | + escape_json(buf, str); |
2199 | 2169 | }
|
0 commit comments