]> granicus.if.org Git - icinga2/commitdiff
Fix incorrect return value for the macro() function
authorGunnar Beutner <gunnar@beutner.name>
Mon, 13 Jul 2015 06:25:19 +0000 (08:25 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 13 Jul 2015 06:25:19 +0000 (08:25 +0200)
fixes #9584

lib/icinga/macroprocessor.cpp

index 177ef9d35743ac6c4cce6a06447db8435d31d6d7..e6a72252b9d6a673609e4f0e64ea497043548aae 100644 (file)
@@ -278,10 +278,11 @@ Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverLis
                                }
 
                                resolved_macro = resolved_arr;
-                       } else
+                       } else if (resolved_macro.IsString()) {
                                resolved_macro = InternalResolveMacros(resolved_macro,
                                        resolvers, cr, missingMacro, EscapeCallback(), Dictionary::Ptr(),
                                        false, recursionLevel + 1);
+                       }
                }
 
                if (!useResolvedMacros && found && resolvedMacros)
@@ -290,7 +291,12 @@ Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverLis
                if (escapeFn)
                        resolved_macro = escapeFn(resolved_macro);
 
-               /* we're done if the value is an array */
+               /* we're done if this is the only macro and there are no other non-macro parts in the string */
+               if (pos_first == 0 && pos_second == str.GetLength() - 1)
+                       return resolved_macro;
+               else if (resolved_macro.IsObjectType<Array>())
+                               BOOST_THROW_EXCEPTION(std::invalid_argument("Mixing both strings and non-strings in macros is not allowed."));
+
                if (resolved_macro.IsObjectType<Array>()) {
                        /* don't allow mixing strings and arrays in macro strings */
                        if (pos_first != 0 || pos_second != str.GetLength() - 1)