Fixed issue with encoding and escaping " and \ when inserting into Postgres Array column.
This commit is contained in:
parent
f0aca1e62f
commit
f6479786b1
@ -332,7 +332,7 @@ class DefaultBindContext extends AbstractBindContext {
|
||||
}
|
||||
else {
|
||||
sb.append("\"");
|
||||
sb.append(o.toString().replaceAll("\"", "\"\""));
|
||||
sb.append(o.toString().replace("\\", "\\\\").replace("\"", "\\\""));
|
||||
sb.append("\"");
|
||||
}
|
||||
|
||||
|
||||
@ -30,4 +30,14 @@ public class PostgresArrayEscapingTest {
|
||||
public void nulls() {
|
||||
assertEquals("{null}", DefaultBindContext.postgresArrayString(new Object[]{null}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringsWithQuotesShouldBeEscaped() {
|
||||
assertEquals("{\"\\\"foo\"}", DefaultBindContext.postgresArrayString(new String[]{"\"foo"}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringsWithBackslashesShouldBeEncoded() {
|
||||
assertEquals("{\"\\\\foo\"}", DefaultBindContext.postgresArrayString(new String[]{"\\foo"}));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user