From ead2d5d55ff949866328c6ddea7d3a257244355a Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Fri, 12 Jun 2020 00:02:32 -0700 Subject: [PATCH] Factoids: correct recursive $var expansion --- PBot/Factoids.pm | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index f2dfed3a..66bac588 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -693,9 +693,9 @@ sub expand_factoid_selectors { my ($article, $trailing) = ($1, $2); my $fixed_article = select_indefinite_article $item; - if ($article eq 'A' or $article eq 'AN') { + if ($article eq 'AN') { $fixed_article = uc $fixed_article; - } elsif ($article eq 'An') { + } elsif ($article eq 'An' or $article eq 'A') { $fixed_article = ucfirst $fixed_article; } @@ -824,15 +824,17 @@ sub expand_factoid_vars { if (not length $replacement) { $result =~ s/\s+$//; + } else { + $replacement = $self->expand_factoid_vars($context, $replacement, %opts); } if ($result =~ s/\b(a|an)(\s+)$//i) { my ($article, $trailing) = ($1, $2); my $fixed_article = select_indefinite_article $replacement; - if ($article eq 'A' or $article eq 'AN') { + if ($article eq 'AN') { $fixed_article = uc $fixed_article; - } elsif ($article eq 'An') { + } elsif ($article eq 'An' or $article eq 'A') { $fixed_article = ucfirst $fixed_article; } @@ -848,13 +850,7 @@ sub expand_factoid_vars { } if ($matches == 0 or $expansions == 0) { - if (length $rest) { - $rest = $result . $rest; - $result = ''; - next; - } else { - last; - } + last; } if (not length $rest) {