Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape \0 in identifiers and literals #2900

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/pg/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ class Client extends EventEmitter {

// Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
escapeIdentifier(str) {
if (str.includes('\0')) {
throw new Error('Identifier contains \\0, which is not allowed in PostgreSQL identifiers')
}
return '"' + str.replace(/"/g, '""') + '"'
}

Expand All @@ -459,6 +462,8 @@ class Client extends EventEmitter {
} else if (c === '\\') {
escaped += c + c
hasBackslash = true
} else if (c === '\0') {
throw new Error('Literal contains \\0, which is not allowed in PostgreSQL strings')
} else {
escaped += c
}
Expand Down