Thread
Commits
-
Fix quoted-substring handling in format parsing for to_char/to_number/etc.
- 63ca86318dc3 11.0 landed
-
Bizarre behavior of literal-substring parsing in formatting.c
Tom Lane <tgl@sss.pgh.pa.us> — 2017-11-17T20:11:26Z
I started to look at handling multibyte data more sanely in formatting.c, and soon noticed that the treatment of literal substrings in parse_format() seemed overly complicated and underly correct, as well as inadequately documented. In particular, it can't make up its mind whether backslash is a quoting character or not. These cases make it look like it is: regression=# select to_char('100'::numeric, 'f"\ool"999'); to_char ---------- fool 100 (1 row) regression=# select to_char('100'::numeric, 'f"\\ool"999'); to_char ----------- f\ool 100 (1 row) regression=# select to_char('100'::numeric, 'f"ool\"999'); to_char ---------- fool"999 (1 row) (Since the second " is quoted, we never escape the literal substring, and the format-code 999 becomes just literal data.) But try this: regression=# select to_char('100'::numeric, 'f"ool\\"999'); to_char ----------- fool\"999 (1 row) The first backslash has quoted the second one, and then reached out and quoted the quote too. That hardly seems sane. Outside double quotes, it seems that backslash is only special when it immediately precedes a double quote. That's not enormously consistent with other string parsers in our code, but it's at least self-consistent, and given the lack of complaints it's probably best not to change that behavior. Accordingly I offer the attached rewrite. Of the new regression test cases, the only one that changes behavior from before is the last one, which is the case I just showed. If no objections, I'll push this shortly. I think putting it in HEAD is enough, given the lack of field complaints. regards, tom lane