From 3f04c9031b291e2b860ec2d52377a06361526988 Mon Sep 17 00:00:00 2001 From: Digimer Date: Mon, 1 Feb 2021 12:27:05 -0500 Subject: [PATCH] * Fixed a bug in Words->parse_banged_string() Where the flattened string wasn't being used for the variable substitutions. * This resolves issue #23. Signed-off-by: Digimer --- Anvil/Tools/Words.pm | 4 ++-- tools/test.pl | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Anvil/Tools/Words.pm b/Anvil/Tools/Words.pm index 3894fa8e..18ddd876 100644 --- a/Anvil/Tools/Words.pm +++ b/Anvil/Tools/Words.pm @@ -399,10 +399,10 @@ sub parse_banged_string # Some variable values will be multi-line strings. We need to replace the new-lines in those # multi-line values into '##br##' so that we can do a proper variable insertion. We can't simply # replace all new-lines, however, as it's normal to have multiple keys, each on their own line. + my $new_string = ""; if ($key_string =~ /\n/gs) { my $in_value = 0; - my $new_string = ""; foreach my $line (split/\n/, $key_string) { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }}); @@ -449,7 +449,7 @@ sub parse_banged_string } # There might be multiple keys, split by newlines. - foreach my $message (split/\n/, $key_string) + foreach my $message (split/\n/, $new_string) { # If we've looped, there will be data in 'out_string" already so append a newline to separate # this key from the previous one. diff --git a/tools/test.pl b/tools/test.pl index 0b314e82..02512052 100755 --- a/tools/test.pl +++ b/tools/test.pl @@ -26,10 +26,44 @@ $anvil->Get->switches; $anvil->Database->connect({debug => 3}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0132"}); -my ($free_minor, $free_port) = $anvil->DRBD->get_next_resource({debug => 2, anvil_uuid => "1aded871-fcb1-4473-9b97-6e9c246fc568"}); -$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { - free_minor => $free_minor, - free_port => $free_port, -}}); +my $key_string = 'scan_drbd_message_0007,!!resource_name!srv00-sql1!!,!!resource_state!#!string!scan_drbd_unit_0004!#!!,!!resource_xml!] from key string: [scan_drbd_message_0007,!!resource_name!srv00-sql1!!,!!resource_state!#!string!scan_drbd_unit_0004!#!!,!!resource_xml! + + + /dev/drbd_srv00-sql1_0 + /dev/mk-a02n01_ssd0/srv00-sql1_0 + internal + +
(null)
+
+ + + /dev/drbd_srv00-sql1_0 + /dev/mk-a02n02_ssd0/srv00-sql1_0 + internal + +
(null)
+
+ +
10.101.12.1
+
10.101.12.2
+
+
+
+
+
+
!!'; +my $out_string = $anvil->Words->parse_banged_string({ + debug => 2, + key_string => $key_string, +}); + +print "Got: +==== +".$out_string." +==== +"; $anvil->nice_exit({exit_code => 0});