@@ -1563,7 +1563,7 @@ func TestSqlInjection(t *testing.T) {
1563
1563
} else if err == nil {
1564
1564
dbt .Errorf ("Sql injection successful with arg: %s" , arg )
1565
1565
} else {
1566
- dbt .Errorf ("Error running query with arg: %s; err: %s" , err .Error ())
1566
+ dbt .Errorf ("Error running query with arg: %s; err: %s" , arg , err .Error ())
1567
1567
}
1568
1568
}
1569
1569
}
@@ -1577,3 +1577,32 @@ func TestSqlInjection(t *testing.T) {
1577
1577
runTests (t , testdsn , createTest ("' OR '1'='1" ))
1578
1578
}
1579
1579
}
1580
+
1581
+ // Test if inserted data is correctly retrieved after being escaped
1582
+ func TestInsertRetrieveEscapedData (t * testing.T ) {
1583
+ testData := func (dbt * DBTest ) {
1584
+ dbt .mustExec ("CREATE TABLE test (v VARCHAR(255))" )
1585
+
1586
+ // All sequences that are escaped by EscapeQuotes and EscapeString
1587
+ v := "foo \x00 \n \r \x1a \" '\\ "
1588
+ dbt .mustExec ("INSERT INTO test VALUES (?)" , v )
1589
+
1590
+ var out string
1591
+ err := dbt .db .QueryRow ("SELECT v FROM test" ).Scan (& out )
1592
+ if err != nil {
1593
+ dbt .Fatalf ("%s" , err .Error ())
1594
+ }
1595
+
1596
+ if out != v {
1597
+ dbt .Errorf ("%q != %q" , out , v )
1598
+ }
1599
+ }
1600
+
1601
+ dsns := []string {
1602
+ dsn ,
1603
+ dsn + "&sql_mode=NO_BACKSLASH_ESCAPES" ,
1604
+ }
1605
+ for _ , testdsn := range dsns {
1606
+ runTests (t , testdsn , testData )
1607
+ }
1608
+ }
0 commit comments