8000 Merge pull request #110 from dylex/master · odd/postgresql-async@d9034c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit d9034c3

Browse files
committed
Merge pull request mauricio#110 from dylex/master
Fix encoding of backslashes in arrays
2 parents 74e9495 + 993f8f1 commit d9034c3

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/column/PostgreSQLColumnEncoderRegistry.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class PostgreSQLColumnEncoderRegistry extends ColumnEncoderRegistry {
131131
"NULL"
132132
} else {
133133
if (this.shouldQuote(item)) {
134-
"\"" + this.encode(item).replaceAllLiterally("\"", """\"""") + "\""
134+
"\"" + this.encode(item).replaceAllLiterally("\\", """\\""").replaceAllLiterally("\"", """\"""") + "\""
135135
} else {
136136
this.encode(item)
137137
}

postgresql-async/src/test/scala/com/github/mauricio/async/db/postgresql/ArrayTypesSpec.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ArrayTypesSpec extends Specification with DatabaseTestHelper {
3434
(smallint_column, text_column, timestamp_column)
3535
values (
3636
'{1,2,3,4}',
37-
'{"some,\"comma,separated,text","another line of text",NULL}',
37+
'{"some,\"comma,separated,text","another line of text","fake\,backslash","real\\,backslash\\",NULL}',
3838
'{"2013-04-06 01:15:10.528-03","2013-04-06 01:15:08.528-03"}'
3939
)"""
4040

@@ -52,7 +52,7 @@ class ArrayTypesSpec extends Specification with DatabaseTestHelper {
5252
executeDdl(handler, insert, 1)
5353
val result = executeQuery(handler, "select * from type_test_table").rows.get
5454
result(0)("smallint_column") === List(1,2,3,4)
55-
result(0)("text_column") === List("some,\"comma,separated,text", "another line of text", null )
55+
result(0)("text_column") === List("some,\"comma,separated,text", "another line of text", "fake,backslash", "real\\,backslash\\", null )
5656
result(0)("timestamp_column") === List(
5757
TimestampWithTimezoneEncoderDecoder.decode("2013-04-06 01:15:10.528-03"),
5858
TimestampWithTimezoneEncoderDecoder.decode("2013-04-06 01:15:08.528-03")
@@ -68,7 +68,7 @@ class ArrayTypesSpec extends Specification with DatabaseTestHelper {
6868
TimestampWithTimezoneEncoderDecoder.decode("2013-04-06 01:15:08.528-03")
6969
)
7070
val numbers = List(1,2,3,4)
71-
val texts = List("some,\"comma,separated,text", "another line of text", null )
71+
val texts = List("some,\"comma,separated,text", "another line of text", "fake,backslash", "real\\,backslash\\", null )
7272

7373
withHandler {
7474
handler =>

postgresql-async/src/test/scala/com/github/mauricio/async/db/postgresql/column/DefaultColumnEncoderRegistrySpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DefaultColumnEncoderRegistrySpec extends Specification {
2626

2727
"correctly render an array of strings with nulls" in {
2828
val items = Array( "some", """text \ hoes " here to be seen""", null, "all, right" )
29-
registry.encode( items ) === """{"some","text \ hoes \" here to be seen",NULL,"all, right"}"""
29+
registry.encode( items ) === """{"some","text \\ hoes \" here to be seen",NULL,"all, right"}"""
3030
}
3131

3232
"correctly render an array of numbers" in {

0 commit comments

Comments
 (0)
0