]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
convert xlat-string to the new method
authorAlan T. DeKok <aland@freeradius.org>
Sun, 21 Aug 2022 14:03:51 +0000 (10:03 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 23 Aug 2022 03:01:01 +0000 (23:01 -0400)
Previously "cast to string" was "print to string" for everything
except octets.  For octets, it was "cast".  That inconsistency
causes issues.

Now, "cast to string" is "print to string" for everything.

If the user wants to *convert* data to a string, the %{string:...}
function can be used.

src/tests/keywords/all.mk
src/tests/keywords/xlat-string

index d5d9391fab6b9670ff5820c4563a5fd36f588a75..7488cf4534b8f0075d04e97474f71c09273071c2 100644 (file)
@@ -41,7 +41,7 @@ test.keywords.${1}: $(addprefix $(OUTPUT)/,${1})
 #  Migration support.  Some of the tests don't run under the new
 #  conditions, so we don't run them under the new conditions.
 #
-ifeq "$(findstring ${1}, paircmp xlat-string xlat-subst if-failed-xlat if-regex-match-comp if-regex-match-named)" ""
+ifeq "$(findstring ${1}, paircmp xlat-subst if-failed-xlat if-regex-match-comp if-regex-match-named)" ""
 $(OUTPUT)/${1}: NEW_COND=-S parse_new_conditions=yes -S use_new_conditions=yes
 endif
 
index f4dd84fb30cf0ed4f12efef875de0c0bfa08f8d8..d493ec3198af0d2f6ad588cb13de83bedd6c3a16 100644 (file)
@@ -1,37 +1,35 @@
 #
 # PRE: update if
 #
-#  Remove all attributes in a list
-#
-update request {
-       &Tmp-Octets-0 := 0x5c5c
-       &Tmp-Octets-1 := 0x49206c696b6520636869636b656e2049206c696b65206c69766572
-       &Tmp-Octets-2 := 0x490049
-       &Tmp-Octets-3 := 0x00
-       &Tmp-Octets-4 := 0x7465737431
-       &Tmp-Octets-5 := 0x7465737432
-}
-
-update request {
-       &Tmp-String-0 := "%{string:%{Tmp-Octets-0}}"
-       &Tmp-String-1 := "%{string:%{Tmp-Octets-1}}"
-       &Tmp-String-2 := "%{string:%{Tmp-Octets-2}}"
-       &Tmp-String-3 := "%{string:%{Tmp-Octets-3}}"
+&request += {
+       &Tmp-Octets-0 = 0x5c5c
+       &Tmp-Octets-1 = 0x49206c696b6520636869636b656e2049206c696b65206c69766572
+       &Tmp-Octets-2 = 0x490049
+       &Tmp-Octets-3 = 0x00
+       &Tmp-Octets-4 = 0x7465737431
+       &Tmp-Octets-5 = 0x7465737432
 }
 
-if (<string>&Tmp-Octets-0 != &Tmp-String-0) {
-       test_fail
-}
-
-if (<string>&Tmp-Octets-1 != &Tmp-String-1) {
-       test_fail
+&request += {
+       &Tmp-String-0 = "%{string:%{Tmp-Octets-0}}"
+       &Tmp-String-1 = "%{string:%{Tmp-Octets-1}}"
+       &Tmp-String-2 = "%{string:%{Tmp-Octets-2}}"
+       &Tmp-String-3 = "%{string:%{Tmp-Octets-3}}"
 }
 
-if (<string>&Tmp-Octets-2 != &Tmp-String-2) {
+#
+#  Cast of octets to string is the octets *printed* to a string, just
+#  like every other data type.  If we want to *convert* the octets to
+#  a string, we have to use "%{string:...}"
+#
+if (<string>&Tmp-Octets-0 != "0x5c5c") {
        test_fail
 }
 
-if (<string>&Tmp-Octets-3 != &Tmp-String-3) {
+#
+#      And the printed "0x5c5c" is not equivalent to the octet string
+#
+if (<string>&Tmp-Octets-0 == 0x5c5c) {
        test_fail
 }
 
@@ -39,7 +37,10 @@ if (&Tmp-String-0 != "\\\\") {
        test_fail
 }
 
-if (<string>&Tmp-Octets-0 != "%{string:%{Tmp-Octets-0}}") {
+#
+#  These are now defined to be different.
+#
+if (<string>&Tmp-Octets-0 == "%{string:%{Tmp-Octets-0}}") {
        test_fail
 }