Skip to content

Commit

Permalink
fix: bytea formatting for new ff (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepansergeevitch authored Mar 25, 2024
1 parent ca753db commit 22f936f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/formatter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ export class QueryFormatter {
}

private escapeBuffer(param: Buffer) {
return "'\\x" + param.toString("hex") + "'";
const bytesFormatted = [];
for (let i = 0; i < param.length; i++) {
bytesFormatted.push("\\x" + param[i].toString(16).padStart(2, "0"));
}
return "E'" + bytesFormatted.join("") + "'";
}

private escapeArray(param: unknown[], prefix = "[", suffix = "]") {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/statement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ describe("format query", () => {
const formattedQuery = queryFormatter.formatQuery(query, [buffer]);
// Jest escaping rules are different, so we need to double the amount of quotes compared to .toEqual()
expect(formattedQuery).toMatchInlineSnapshot(
`"SELECT 'hello_world'::bytea == '\\\\x68656c6c6f5f776f726c64'"`
`"SELECT 'hello_world'::bytea == E'\\\\x68\\\\x65\\\\x6c\\\\x6c\\\\x6f\\\\x5f\\\\x77\\\\x6f\\\\x72\\\\x6c\\\\x64'"`
);
});
});
Expand Down

0 comments on commit 22f936f

Please sign in to comment.