Skip to content

Commit 1518bc8

Browse files
Fix Matches in Emails
Fix Matches in Emails
1 parent c735bc6 commit 1518bc8

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

MerlinAU.sh

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
#
55
# Original Creation Date: 2023-Oct-01 by @ExtremeFiretop.
66
# Official Co-Author: @Martinski W. - Date: 2023-Nov-01
7-
# Last Modified: 2025-Jun-08
7+
# Last Modified: 2025-Jun-17
88
###################################################################
99
set -u
1010

1111
## Set version for each Production Release ##
12-
readonly SCRIPT_VERSION=1.4.8
12+
readonly SCRIPT_VERSION=1.4.9
1313
readonly SCRIPT_NAME="MerlinAU"
1414
## Set to "master" for Production Releases ##
1515
SCRIPT_BRANCH="master"
@@ -3033,9 +3033,9 @@ _GetLatestFWUpdateVersionFromRouter_()
30333033
echo "$newVersionStr" ; return "$retCode"
30343034
}
30353035

3036-
##----------------------------------------##
3037-
## Modified by Martinski W. [2024-Apr-14] ##
3038-
##----------------------------------------##
3036+
##------------------------------------------##
3037+
## Modified by ExtremeFiretop [2025-Jun-17] ##
3038+
##------------------------------------------##
30393039
_CreateEMailContent_()
30403040
{
30413041
if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi
@@ -3136,35 +3136,34 @@ _CreateEMailContent_()
31363136
;;
31373137
STOP_FW_UPDATE_APPROVAL)
31383138
emailBodyTitle="WARNING"
3139+
high_risk_regex=$(printf '%s\n' "$high_risk_terms" | sed 's/ /[[:space:]]+/g')
31393140
if "$isEMailFormatHTML"
31403141
then
31413142
# Highlight high-risk terms using HTML with a yellow background #
3142-
highlighted_changelog_contents="$(echo "$changelog_contents" | sed -E "s/($high_risk_terms)/<span style='background-color:yellow;'>\1<\/span>/gi")"
3143+
highlighted_changelog_contents="$(
3144+
printf '%s\n' "$changelog_contents" |
3145+
sed -E ":a;N;\$!ba; \
3146+
s/(${high_risk_regex})/<span style='background-color:yellow;'>\\1<\\/span>/Ig"
3147+
)"
31433148
else
31443149
# Step 1: Enclose matched terms with unique markers that don't conflict with '>' and '<'
3145-
highlighted_changelog_contents="$(echo "$changelog_contents" | sed -E "s/($high_risk_terms)/\[\[UPPER\]\]\1\[\[ENDUPPER\]\]/gi")"
3146-
3147-
# Step 2: Modify the awk script with correct marker lengths
3148-
highlighted_changelog_contents="$(echo "$highlighted_changelog_contents" | awk '
3149-
BEGIN {
3150-
upper_marker = "[[UPPER]]"
3151-
endupper_marker = "[[ENDUPPER]]"
3152-
upper_marker_length = length(upper_marker)
3153-
endupper_marker_length = length(endupper_marker)
3154-
}
3155-
{
3156-
while (match($0, /\[\[UPPER\]\][^\[]*\[\[ENDUPPER\]\]/)) {
3157-
prefix = substr($0, 1, RSTART - 1)
3158-
match_text_start = RSTART + upper_marker_length
3159-
match_text_length = RLENGTH - upper_marker_length - endupper_marker_length
3160-
match_text = substr($0, match_text_start, match_text_length)
3161-
suffix = substr($0, RSTART + RLENGTH)
3162-
match_text_upper = toupper(match_text)
3163-
$0 = prefix ">" match_text_upper "<" suffix
3164-
}
3165-
print
3166-
}
3167-
')"
3150+
highlighted_changelog_contents="$(
3151+
printf '%s\n' "$changelog_contents" |
3152+
awk -v regex="$high_risk_regex" '
3153+
BEGIN { IGNORECASE = 1 }
3154+
{ buf = buf $0 ORS } # slurp into buf
3155+
END {
3156+
out = ""
3157+
while (match(buf, regex)) {
3158+
pre = substr(buf, 1, RSTART - 1)
3159+
hit = substr(buf, RSTART, RLENGTH)
3160+
buf = substr(buf, RSTART + RLENGTH) # delete hit + prefix
3161+
out = out pre ">" toupper(hit) "<" # grow output
3162+
}
3163+
out = out buf # tail with no more matches
3164+
printf "%s", out
3165+
}'
3166+
)"
31683167
fi
31693168
{
31703169
echo "Found high-risk phrases in the changelog file while Auto-Updating to version <b>${fwNewUpdateVersion}</b> on the <b>${MODEL_ID}</b> router."

0 commit comments

Comments
 (0)