Quoting =~ in unlang on string expansion

Walter Schober walter.schober at neotel.at
Mon Sep 13 15:32:57 CEST 2021


Hi folks!

String expansion is behaving different in case just adding a string or being a result in a regex compare.

(1)           if (&Called-Station-ID =~ /%{reply:FeatureA}/) {
(1)           EXPAND %{reply:FeatureA}
(1)              --> \^\(3\[0-79]\|38\[0-25-9]\|4\[014-9]\|42\[123]\|29\[89]\|43\[1-6]\|43800\|43720)
(1) ERROR: \^\(3\[0-79]\|38\[0-25-9]\|4\[014-9]\|42\[123]\|29\[89]\|43\[1-6]\|43800\|43720)
(1) ERROR:                                                                              ^ Pattern compilation failed: unmatched parentheses
(1)           ERROR: Failed retrieving values required to evaluate condition

Sure this does not compile because it quoted "(" but not ")". 

In this use case some chars in the reply string are quoted: ^(|[ are quoted while ]) are not for some reasons
But adding the reply value to some debug AVPair this is done without quoting:

This shows the real content of the reply attr:

(1)           else {
(1)             update control {
(1)               Auth-Type := Reject
(1)             } # update control = noop
(1)             update reply {
(1)               EXPAND block=%{reply:FeatureA}
(1)                  --> block=^(3[0-79]|38[0-25-9]|4[014-9]|42[123]|29[89]|43[1-6]|43800|43720)
(1)               Generic-Debug := block=^(3[0-79]|38[0-25-9]|4[014-9]|42[123]|29[89]|43[1-6]|43800|43720)

I was looking through source code why this is happening, but I am lost. Any hint to source code is appreciated.

I'm using version from Debian Buster Backports: 3.0.21+dfsg-1~bpo10+1
I tried a lot already: "/%{}/", /"%{}"/, %{unescape:...}, ... even if (&Called-Station-ID =~ /&reply:FeatureA/) (which results in FALSE always)

Why are some character quoted here in this expansion?
Where are the "safe charaters" defined for unlang compare operator?

Greetings,
Walter





More information about the Freeradius-Users mailing list