File tree Expand file tree Collapse file tree 2 files changed +20
-18
lines changed
Expand file tree Collapse file tree 2 files changed +20
-18
lines changed Original file line number Diff line number Diff line change @@ -66,24 +66,7 @@ function typeHandlers(types) {
6666}
6767
6868module . 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, '""' ) + '"'
8770}
8871
8972const type = {
Original file line number Diff line number Diff line change @@ -578,6 +578,13 @@ t('listen and notify with weird name', async() => {
578578 ) ]
579579} )
580580
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+
581588t ( 'listen reconnects' , async ( ) => {
582589 const listener = postgres ( options )
583590 , xs = [ ]
@@ -731,6 +738,18 @@ t('sql().finally throws not tagged error', async() => {
731738 return [ 'NOT_TAGGED_CALL' , error ]
732739} )
733740
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+
734753t ( 'dynamic column name' , async ( ) => {
735754 return [ '!not_valid' , Object . keys ( ( await sql `select 1 as ${ sql ( '!not_valid' ) } ` ) [ 0 ] ) [ 0 ] ]
736755} )
You can’t perform that action at this time.
0 commit comments