Fixed issue with encoding and escaping " and \ when inserting into Postgres Array column.

This commit is contained in:
Henrik Johansson 2012-10-26 16:37:27 +02:00 committed by Lukas Eder
parent f0aca1e62f
commit f6479786b1
2 changed files with 11 additions and 1 deletions

View File

@ -332,7 +332,7 @@ class DefaultBindContext extends AbstractBindContext {
}
else {
sb.append("\"");
sb.append(o.toString().replaceAll("\"", "\"\""));
sb.append(o.toString().replace("\\", "\\\\").replace("\"", "\\\""));
sb.append("\"");
}

View File

@ -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"}));
}
}