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

fix: fix parameters not being replaced when after $$ strings #15307

Merged
merged 1 commit into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/utils/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function injectReplacements(
const remainingString = sqlString.slice(i, sqlString.length);

const dollarStringStartMatch = remainingString.match(/^\$(?<name>[a-z_][0-9a-z_])?(\$)/i);
const tagName = dollarStringStartMatch?.groups?.name;
const tagName = dollarStringStartMatch?.groups?.name || '';
if (currentDollarStringTagName === tagName) {
currentDollarStringTagName = null;
}
Expand Down
18 changes: 18 additions & 0 deletions test/unit/utils/sql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ describe('injectReplacements (named replacements)', () => {
});
});

it('does consider the token to be a bind parameter if it is located after a $ quoted string', () => {
const sql = injectReplacements('SELECT $$ abc $$ AS string FROM users WHERE id = :id', dialect, {
id: 1
});

expectsql(sql, {
default: 'SELECT $$ abc $$ AS string FROM users WHERE id = 1'
});
});

it('does not consider the token to be a bind parameter if it is part of a string with a backslash escaped quote, in dialects that support backslash escape', () => {
expectPerDialect(
() =>
Expand Down Expand Up @@ -377,6 +387,14 @@ describe('injectReplacements (positional replacements)', () => {
});
});

it('does consider the token to be a bind parameter if it is located after a $ quoted string', () => {
const sql = injectReplacements('SELECT $$ abc $$ AS string FROM users WHERE id = ?', dialect, [1]);

expectsql(sql, {
default: 'SELECT $$ abc $$ AS string FROM users WHERE id = 1'
});
});

it('does not consider the token to be a replacement if it is part of a string with a backslash escaped quote', () => {
const test = () =>
injectReplacements(
Expand Down