Skip to content

Commit b8867b9

Browse files
authored
Fix: Corrige padrões de sanitização de LIMIT e OFFSET para consideraram valores maiúsculos e minúsculos (#26)
* Fix para tratar OFFSET e LIMIT maiúsculos e minúsculos
1 parent 439460d commit b8867b9

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/Support/SqlSanitizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public function sanitize(string $sql): string
2222
'/(?<=\()\d+(?=,\s)/',
2323
'/(?<=,\s)\d+(?=,\s)/',
2424
'/(?<=,\s)\d+(?=\))/',
25-
'/(?<=LIMIT\s)\d+/',
26-
'/(?<=OFFSET\s)\d+/',
25+
'/(?<=LIMIT\s)\d+/i',
26+
'/(?<=OFFSET\s)\d+/i',
2727
];
2828

2929
return preg_replace($patterns, array_fill(0, count($patterns), '?'), $sql);

tests/Cases/SqlSanitizerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,15 @@ public function testSanitizeLimitAndOffset(): void
6363
'select * from `cards` where `user_id` in (?) LIMIT ? OFFSET ?',
6464
$sanitizer->sanitize('select * from `cards` where `user_id` in (1) LIMIT 100 OFFSET 100')
6565
);
66+
67+
self::assertSame(
68+
'select * from `cards` where `user_id` in (?) limit ?',
69+
$sanitizer->sanitize('select * from `cards` where `user_id` in (1) limit 100')
70+
);
71+
72+
self::assertSame(
73+
'select * from `cards` where `user_id` in (?) limit ? offset ?',
74+
$sanitizer->sanitize('select * from `cards` where `user_id` in (1) limit 100 offset 100')
75+
);
6676
}
6777
}

0 commit comments

Comments
 (0)