Skip to content

Commit 1a01082

Browse files
Conditions wrap (#5535)
* Added parentheses wrapping for `not`, `or`, `and` operators, related tests; removed leftover debug file * Synced postpone date, test case fix * Additional test fixes * beta.20 --------- Co-authored-by: AndriiSherman <andreysherman11@gmail.com>
1 parent 01d681d commit 1a01082

File tree

26 files changed

+14050
-8763
lines changed

26 files changed

+14050
-8763
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- Fixed `sql.identifier()`, `sql.as()` escaping issues. Previously all the values passed to this functions were not properly escaped
2+
causing a possible SQL Injection (CWE-89) vulnerability
3+
4+
Thanks to @EthanKim88, @0x90sh and @wgoodall01 for reaching out to us with a reproduction and suggested fix

drizzle-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-kit",
3-
"version": "1.0.0-beta.19",
3+
"version": "1.0.0-beta.20",
44
"homepage": "https://orm.drizzle.team",
55
"keywords": [
66
"drizzle",

drizzle-kit/tests/postgres/pg-constraints.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,7 +2419,7 @@ test('generated + unique', async (t) => {
24192419
expect(st).toStrictEqual([
24202420
`ALTER TABLE \"table\" RENAME COLUMN \"column2\" TO \"column3\";`,
24212421
`ALTER TABLE \"table\" DROP COLUMN \"bool\";`,
2422-
`ALTER TABLE \"table\" ADD COLUMN \"bool\" boolean GENERATED ALWAYS AS (((\"table\".\"column1\" is null) and (\"table\".\"column3\" is null))) STORED;`,
2422+
`ALTER TABLE \"table\" ADD COLUMN \"bool\" boolean GENERATED ALWAYS AS ((((\"table\".\"column1\" is null)) and ((\"table\".\"column3\" is null)))) STORED;`,
24232423
'ALTER TABLE "table" ADD CONSTRAINT "table_bool_key" UNIQUE("bool");',
24242424
]);
24252425
// push is not triggered on generated change
@@ -2467,7 +2467,7 @@ test('generated + pk', async (t) => {
24672467
expect(st).toStrictEqual([
24682468
`ALTER TABLE \"table\" RENAME COLUMN \"column2\" TO \"column3\";`,
24692469
`ALTER TABLE \"table\" DROP COLUMN \"bool\";`,
2470-
`ALTER TABLE \"table\" ADD COLUMN \"bool\" boolean PRIMARY KEY GENERATED ALWAYS AS (((\"table\".\"column1\" is null) and (\"table\".\"column3\" is null))) STORED;`,
2470+
`ALTER TABLE \"table\" ADD COLUMN \"bool\" boolean PRIMARY KEY GENERATED ALWAYS AS ((((\"table\".\"column1\" is null)) and ((\"table\".\"column3\" is null)))) STORED;`,
24712471
]);
24722472
// push is not triggered on generated change
24732473
expect(pst).toStrictEqual([

drizzle-kit/tests/postgres/pg-indexes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ test('index #4', async (t) => {
570570
expect(st).toStrictEqual([
571571
`ALTER TABLE \"table\" RENAME COLUMN \"column2\" TO \"column3\";`,
572572
`ALTER TABLE \"table\" DROP COLUMN \"bool\";`,
573-
`ALTER TABLE \"table\" ADD COLUMN \"bool\" boolean GENERATED ALWAYS AS (((\"table\".\"column1\" is null) and (\"table\".\"column3\" is null))) STORED;`,
573+
`ALTER TABLE \"table\" ADD COLUMN \"bool\" boolean GENERATED ALWAYS AS ((((\"table\".\"column1\" is null)) and ((\"table\".\"column3\" is null)))) STORED;`,
574574
`CREATE INDEX "table_uid_bool_idx" ON "table" ("uid","bool");`,
575575
]);
576576
// push is not triggered on generated change

drizzle-kit/tests/postgres/pg-views.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,7 @@ test('.as in view select', async () => {
20452045
.from(user)
20462046
.leftJoin(
20472047
userSubscription,
2048-
sql`(${user.id} = ${userSubscription.userId} and (${userSubscription.status} = 'active' or ${userSubscription.status} = 'trialing'))`,
2048+
sql`((${user.id} = ${userSubscription.userId}) and (((${userSubscription.status} = 'active') or (${userSubscription.status} = 'trialing'))))`,
20492049
);
20502050
},
20512051
);
@@ -2084,8 +2084,8 @@ test('.as in view select', async () => {
20842084
const expectedSt1View = (viewName: string) =>
20852085
`CREATE VIEW "${viewName}" AS `
20862086
+ `(select "user"."id" as "userId", "user"."email", "user"."name", "user_subscription"."id" as "subscriptionId", "user_subscription"."status" `
2087-
+ `from "user" left join "user_subscription" on ("user"."id" = "user_subscription"."userId" `
2088-
+ `and ("user_subscription"."status" = 'active' or "user_subscription"."status" = 'trialing')));`;
2087+
+ `from "user" left join "user_subscription" on (("user"."id" = "user_subscription"."userId") `
2088+
+ `and ((("user_subscription"."status" = 'active') or ("user_subscription"."status" = 'trialing')))));`;
20892089
const expectedSt1 = [
20902090
'CREATE TABLE "user" (\n\t"id" serial PRIMARY KEY,\n\t"email" text,\n\t"name" text\n);\n',
20912091
'CREATE TABLE "user_subscription" (\n\t"id" serial PRIMARY KEY,\n\t"userId" integer,\n\t"status" text\n);\n',

drizzle-orm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-orm",
3-
"version": "1.0.0-beta.19",
3+
"version": "1.0.0-beta.20",
44
"description": "Drizzle ORM package for SQL databases",
55
"type": "module",
66
"scripts": {

0 commit comments

Comments
 (0)