Unexpected compilation error with if() and local vars
Based on the local variables docs and the regexp capturing docs, I wrote a little statement to extract an interesting part of our request URLs for later use:
set var.zoom = if(req.http.x-normalized-url ~ "/(\d{1-2})/\d+/\d+\.[^/]*$", std.atoi(re.group.2), 0);
But this seems to fail with a compilation error:
Expected CNUM got 'if'
(program line 148), at
(input Line 356 Pos 18)
set var.zoom = if(req.http.x-normalized-url ~ "/(\d{1-2})/\d+/\d+\.[^/]*$", std.atoi(re.group.2), 0);
-----------------##---------------------------------------------------------------------------------------
It looks as though the compiler is expecting a number on the right side of the set
command and if
isn’t satisfying that requirement.
When I rewrote the single-line if
like so:
if (req.http.x-normalized-url ~ "/(\d{1-2})/\d+/\d+\.[^/]*$") {
set var.zoom = std.atoi(re.group.2);
}
…it compiled without problem.
Is this a bug in the compiler? Or am I misunderstanding something?
Please sign in to leave a comment.
Comments
4 comments