Skip to content
Open
Changes from all 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
35 changes: 8 additions & 27 deletions packages/pg/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,36 +173,17 @@
}

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
} else {
escaped += c
}
}

escaped += "'"

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

return escaped
let hasBackslash = false
let escaped = str

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

View workflow job for this annotation

GitHub Actions / lint

'escaped' is never reassigned. Use 'const' instead
.replace(/\\/g, () => {

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

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
hasBackslash = true

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

View workflow job for this annotation

GitHub Actions / lint

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

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

View workflow job for this annotation

GitHub Actions / lint

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

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

View workflow job for this annotation

GitHub Actions / lint

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

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

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
return hasBackslash ? ` E'${escaped}'` : `'${escaped}'`
}

module.exports = {
Expand Down
Loading