File tree Expand file tree Collapse file tree 2 files changed +18
-7
lines changed
Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -9,11 +9,13 @@ const Literal = require('./literals').Literal;
99
1010module . exports = SqlString ;
1111
12- SqlString . __escape = SqlString . escape ;
12+ if ( ! SqlString . __escape ) {
13+ SqlString . __escape = SqlString . escape ;
1314
14- SqlString . escape = function ( val , stringifyObjects , timeZone ) {
15- if ( val instanceof Literal ) {
16- return val . toString ( ) ;
17- }
18- return SqlString . __escape ( val , stringifyObjects , timeZone ) ;
19- } ;
15+ SqlString . escape = function ( val , stringifyObjects , timeZone ) {
16+ if ( val instanceof Literal ) {
17+ return val . toString ( ) ;
18+ }
19+ return SqlString . __escape ( val , stringifyObjects , timeZone ) ;
20+ } ;
21+ }
Original file line number Diff line number Diff line change @@ -17,5 +17,14 @@ describe('sqlstring.test.js', function() {
1717 assert . equal ( SqlString . escape ( literals . Literal ( 'sum2()' ) ) , 'sum2()' ) ;
1818 assert . equal ( SqlString . escape ( literals . now ) , mysql . escape ( literals . now ) ) ;
1919 } ) ;
20+
21+ it ( 'should only patch once' , function ( ) {
22+ require . cache [ require . resolve ( '../lib/sqlstring' ) ] = null ;
23+ const AnotherSqlString = require ( '../lib/sqlstring' ) ;
24+ assert . equal ( AnotherSqlString . escape ( literals . now ) , 'now()' ) ;
25+ assert . equal ( AnotherSqlString . escape ( new literals . Literal ( 'sum' ) ) , 'sum' ) ;
26+ assert . equal ( AnotherSqlString . escape ( literals . Literal ( 'sum2()' ) ) , 'sum2()' ) ;
27+ assert . equal ( AnotherSqlString . escape ( literals . now ) , mysql . escape ( literals . now ) ) ;
28+ } ) ;
2029 } ) ;
2130} ) ;
You can’t perform that action at this time.
0 commit comments