File tree Expand file tree Collapse file tree 1 file changed +32
-9
lines changed Expand file tree Collapse file tree 1 file changed +32
-9
lines changed Original file line number Diff line number Diff line change @@ -177,19 +177,42 @@ const escapeLiteral = function (str) {
177177 return "''"
178178 }
179179 let hasBackslash = false
180- let escaped = str
181- . replace ( / \\ / g, ( ) => {
180+ if ( str . length < 15 ) {
181+ let escaped = "'"
182+
183+ for ( let i = 0 ; i < str . length ; i ++ ) {
184+ const c = str [ i ]
185+ if ( c === "'" ) {
186+ escaped += c + c
187+ } else if ( c === '\\' ) {
188+ escaped += c + c
182189 hasBackslash = true
183- return '\\\\'
184- } )
185- . replace ( / ' / g, "''" )
190+ } else {
191+ escaped += c
192+ }
193+ }
194+
195+ escaped += "'"
186196
187- if ( hasBackslash ) {
188- escaped = ` E'${ escaped } '`
197+ if ( hasBackslash === true ) {
198+ escaped = ' E' + escaped
199+ }
200+ return escaped
189201 } else {
190- escaped = `'${ escaped } '`
202+ let escaped = str
203+ . replace ( / \\ / g, ( ) => {
204+ hasBackslash = true
205+ return '\\\\'
206+ } )
207+ . replace ( / ' / g, "''" )
208+
209+ if ( hasBackslash ) {
210+ escaped = ` E'${ escaped } '`
211+ } else {
212+ escaped = `'${ escaped } '`
213+ }
214+ return escaped
191215 }
192- return escaped
193216}
194217
195218module . exports = {
You can’t perform that action at this time.
0 commit comments