Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 35 additions & 24 deletions packages/pg/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,36 +173,47 @@
}

const escapeLiteral = function (str) {
let hasBackslash = false
let escaped = "'"

if (str == null) {
return "''"
}

if (typeof str !== 'string') {
return "''"
}

for (let i = 0; i < str.length; i++) {
const c = str[i]
if (c === "'") {
escaped += c + c
} else if (c === '\\') {
escaped += c + c
hasBackslash = true
let hasBackslash = false
if (str.length < 13) {
// This methid is a bit faster for short strings
let escaped = "'"

for (let i = 0; i < str.length; i++) {
const c = str[i]
if (c === "'") {
escaped += c + c
} else if (c === '\\') {
escaped += c + c
hasBackslash = true
} else {
escaped += c
}
}

Check failure on line 195 in packages/pg/lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
escaped += "'"

Check failure on line 197 in packages/pg/lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
if (hasBackslash === true) {
escaped = ' E' + escaped
}
return escaped
} else {
let escaped = str
.replace(/\\/g, () => {

Check failure on line 204 in packages/pg/lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
hasBackslash = true

Check failure on line 205 in packages/pg/lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

Delete `····`
return '\\\\'

Check failure on line 206 in packages/pg/lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

Replace `············` with `········`
})

Check failure on line 207 in packages/pg/lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
.replace(/'/g, "''")

Check failure on line 208 in packages/pg/lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

Replace `········` with `······`

Check failure on line 209 in packages/pg/lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

Delete `····`
if (hasBackslash) {
escaped = ` E'${escaped}'`

Check failure on line 211 in packages/pg/lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
} else {
escaped += c
escaped = `'${escaped}'`

Check failure on line 213 in packages/pg/lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
}
return escaped
}

escaped += "'"

if (hasBackslash === true) {
escaped = ' E' + escaped
}

return escaped
}

module.exports = {
Expand Down