File tree Expand file tree Collapse file tree 4 files changed +37
-2
lines changed Expand file tree Collapse file tree 4 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 1
1
Revision history for SQL::Abstract
2
2
3
+ - Fix overly-enthusiastic parenthesis unroller (RT#99503)
4
+
3
5
revision 1.80 2014-10-05
4
6
----------------------------
5
7
- Fix erroneous behavior of is_literal_value($) wrt { -ident => ... }
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ requires 'Exporter' => '5.57';
22
22
requires ' MRO::Compat' => ' 0.12' ;
23
23
requires ' Moo' => ' 1.004002' ;
24
24
requires ' Hash::Merge' => ' 0.12' ;
25
+ requires ' Text::Balanced' => ' 2.00' ;
25
26
26
27
test_requires " Test::More" => ' 0.88' ;
27
28
test_requires " Test::Exception" => ' 0.31' ;
Original file line number Diff line number Diff line change @@ -1242,8 +1242,29 @@ sub _where_field_IN {
1242
1242
# adding them back in the corresponding method
1243
1243
sub _open_outer_paren {
1244
1244
my ($self , $sql ) = @_ ;
1245
- $sql = $1 while $sql =~ / ^ \s * \( (.*) \) \s * $ /xs ;
1246
- return $sql ;
1245
+
1246
+ while ( my ($inner ) = $sql =~ / ^ \s * \( (.*) \) \s * $ /xs ) {
1247
+
1248
+ # there are closing parens inside, need the heavy duty machinery
1249
+ # to reevaluate the extraction starting from $sql (full reevaluation)
1250
+ if ( $inner =~ / \) / ) {
1251
+ require Text::Balanced;
1252
+
1253
+ my (undef , $remainder ) = do {
1254
+ # idiotic design - writes to $@ but *DOES NOT* throw exceptions
1255
+ local $@ ;
1256
+ Text::Balanced::extract_bracketed( $sql , ' ()' , qr /\s */ );
1257
+ };
1258
+
1259
+ # the entire expression needs to be a balanced bracketed thing
1260
+ # (after an extract no remainder sans trailing space)
1261
+ last if defined $remainder and $remainder =~ / \S / ;
1262
+ }
1263
+
1264
+ $sql = $inner ;
1265
+ }
1266
+
1267
+ $sql ;
1247
1268
}
1248
1269
1249
1270
Original file line number Diff line number Diff line change @@ -174,6 +174,17 @@ my @in_between_tests = (
174
174
bind => [],
175
175
test => ' -in multi-line subquery test' ,
176
176
},
177
+
178
+ # check that the outer paren opener is not too agressive
179
+ # note: this syntax *is not legal* on SQLite (maybe others)
180
+ # see end of https://rt.cpan.org/Ticket/Display.html?id=99503
181
+ {
182
+ where => { foo => { -in => \ ' (SELECT 1) UNION (SELECT 2)' } },
183
+ stmt => ' WHERE foo IN ( (SELECT 1) UNION (SELECT 2) )' ,
184
+ bind => [],
185
+ test => ' -in paren-opening works on balanced pairs only' ,
186
+ },
187
+
177
188
{
178
189
where => {
179
190
customer => { -in => \[
You can’t perform that action at this time.
0 commit comments