Commit f471857
committed
Fix string escaping when standard_conforming_strings is 'off'
Ignore-this: 2f27bc24aa303a41fea7cd469dac2ac4
PostGreSQL supports two different string escaping syntax:
- the standard SQL escape convention is to put string literals between
single quotes, and double them inside: 'foo''bar' for "foo'bar"
- the non-standard "C-style escaping" allows usual backquote escaping
of \n,\r,\\ etc. when the literal is marked with a E:
E'foo\'bar'. Note that both "\n" and "\\n" are then interpreted as
the end-of-line character.
When the standard_conforming_strings flag is off, which is the default
value for PostGreSQL before 9.1, C-style escaping is also allowed in
standard string literals (without E); this means that the string
literal 'foo\', while accepted by the SQL standard, is
a non-terminated string literal when interpreted by old versions of
PostgreSQL, which might raise SQL injections concerns.
The fix is to use E everywhere and protect against all
backslashes. This forces us into the relatively nonsensical
non-standard mode, but at least the behavior is consistent across all
PostgreSQL versions and configurations.
darcs-hash:20121219154827-a85e5-c1ab1535f67bdaf073517c373f54b40019d025fd1 parent 5779526 commit f471857
1 file changed
+3
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
150 | 152 | | |
151 | 153 | | |
152 | 154 | | |
153 | | - | |
| 155 | + | |
154 | 156 | | |
155 | 157 | | |
156 | 158 | | |
| |||
0 commit comments