Skip to content

Commit

Permalink
rest: fix detection of calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Oct 10, 2024
1 parent dea143a commit 59d8398
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Thruk/Controller/rest_v1.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2893,7 +2893,7 @@ sub _parse_columns_data {
$name = shift @arg;
push(@{$functions}, [$f, \@arg]);
}
if(scalar @{$functions} == 0 && $name =~ m/[\+\*\-\/]/gmx) {
if(scalar @{$functions} == 0 && $name =~ m/.+[\+\*\-\/].+/gmx && $raw->[$x] !~ m/^`.*`$/mx) { # NO CRITIC BACKTICKS
my $f = "_calc";
push(@{$functions}, [$f, [$name]]);
}
Expand Down
1 change: 1 addition & 0 deletions t/092-backticks.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ for my $cmd (@{$cmds}) {
chomp($line);
$line =~ s/'.*?'//gmx;
next if $line =~ m/nasty\ chars/mx;
next if $line =~ m/NO\ CRITIC\ BACKTICKS/mx;
$line =~ s/\#.*$//gmx;
next if($filter && $line !~ m%$filter%mx);
next if $line =~ m%\QThruk/Utils/IO.pm:\E%mx;
Expand Down
23 changes: 22 additions & 1 deletion t/scenarios/rest_api/t/local/rest_api_misc.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BEGIN {
require TestUtils;
import TestUtils;
}
plan tests => 76;
plan tests => 94;

###########################################################
# test thruks script path
Expand Down Expand Up @@ -114,3 +114,24 @@ $ENV{'THRUK_TEST_AUTH_USER'} = "omdadmin";
}

###########################################################
{
# make sure / columns do not interfer with calculations
TestUtils::test_command({
cmd => '/usr/bin/env thruk r \'/services?columns=name,/\'',
like => ['/"\/"\s*:\s*\d+,/'],
});
TestUtils::test_command({
cmd => '/usr/bin/env thruk r \'/services?columns=name,`/`\'',
like => ['/"\/"\s*:\s*\d+,/'],
});
TestUtils::test_command({
cmd => '/usr/bin/env thruk r \'/services?columns=name,`/`,latency/5\'',
like => ['/"\/"\s*:\s*\d+,/', '/"latency\/5"/'],
});
TestUtils::test_command({
cmd => '/usr/bin/env thruk r \'/services?columns=name,/,latency/5\'',
like => ['/"\/"\s*:\s*\d+,/', '/"latency\/5"/'],
});
}

###########################################################

0 comments on commit 59d8398

Please sign in to comment.