File tree 2 files changed +20
-18
lines changed
2 files changed +20
-18
lines changed Original file line number Diff line number Diff line change @@ -66,24 +66,7 @@ function typeHandlers(types) {
66
66
}
67
67
68
68
module . exports . escape = function escape ( str ) {
69
- let result = ''
70
- let q = str [ 0 ] < 10 || str [ 0 ] === '$'
71
- let last = 0
72
- let c
73
-
74
- for ( let i = 0 ; i < str . length ; i ++ ) {
75
- c = str [ i ] . charCodeAt ( 0 )
76
- if ( str [ i ] === '"' ) {
77
- q = true
78
- result += str . slice ( last , i ) + '"'
79
- last = i
80
- } else if ( c === 96 || ( c !== 36 && c <= 47 ) || ( c >= 58 && c <= 64 )
81
- || ( c >= 91 && c <= 94 ) || ( c >= 123 && c <= 128 ) ) {
82
- q = true
83
- }
84
- }
85
-
86
- return ( q ? '"' : '' ) + ( q ? result + str . slice ( last , str . length ) : str ) + ( q ? '"' : '' )
69
+ return '"' + str . replace ( / " / g, '""' ) + '"'
87
70
}
88
71
89
72
const type = {
Original file line number Diff line number Diff line change @@ -578,6 +578,13 @@ t('listen and notify with weird name', async() => {
578
578
) ]
579
579
} )
580
580
581
+ t ( 'listen and notify with upper case' , async ( ) =>
582
+ [ 'works' , await new Promise ( async resolve => {
583
+ await sql . listen ( 'withUpperChar' , resolve )
584
+ sql . notify ( 'withUpperChar' , 'works' )
585
+ } ) ]
586
+ )
587
+
581
588
t ( 'listen reconnects' , async ( ) => {
582
589
const listener = postgres ( options )
583
590
, xs = [ ]
@@ -731,6 +738,18 @@ t('sql().finally throws not tagged error', async() => {
731
738
return [ 'NOT_TAGGED_CALL' , error ]
732
739
} )
733
740
741
+ t ( 'little bobby tables' , async ( ) => {
742
+ const name = 'Robert\'); DROP TABLE students;--'
743
+
744
+ await sql `create table students (name text, age int)`
745
+ await sql `insert into students (name) values (${ name } )`
746
+
747
+ return [
748
+ name , ( await sql `select name from students` ) [ 0 ] . name ,
749
+ await sql `drop table students`
750
+ ]
751
+ } )
752
+
734
753
t ( 'dynamic column name' , async ( ) => {
735
754
return [ '!not_valid' , Object . keys ( ( await sql `select 1 as ${ sql ( '!not_valid' ) } ` ) [ 0 ] ) [ 0 ] ]
736
755
} )
You can’t perform that action at this time.
0 commit comments