Skip to content

Commit ad0c498

Browse files
committed
FIX: Keep bracketed strings in service descriptions in hover menu
The dynamic macro pass in ElementHover.js runs over the whole template after the child rows have been substituted, so a bracketed string that is part of a child value (e.g. a service description like "Switch1 [xxx]") was mistaken for an unknown macro and dropped, leaving only "Switch1". Preserve the original "[name]" text for tokens that are not actual macros, using hasOwnProperty so that defined macros holding a legitimately empty value (e.g. an empty plugin output) are still replaced correctly.
1 parent 20bf85a commit ad0c498

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FIX: Hover menu no longer strips bracketed strings (e.g. "[xxx]") from service descriptions

share/frontend/nagvis-js/js/ElementHover.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,14 @@ const ElementHover = Element.extend({
562562
if (this.obj.conf.hover_childs_show && this.obj.conf.hover_childs_show == "1")
563563
template_html = this.replaceChildMacros(template_html);
564564

565-
// Replace all normal macros
566-
template_html = template_html.replace(/\[(\w*)\]/g, function () {
567-
return oMacros[arguments[1]] || "";
565+
// Replace all normal macros. This pass also runs over the already
566+
// substituted child rows, so a bracketed string that is part of a
567+
// child value (e.g. a service description like "Switch1 [xxx]") must
568+
// not be mistaken for an unknown macro and dropped. Keep the original
569+
// "[name]" text for tokens that are not actual macros, while still
570+
// replacing defined macros that legitimately hold an empty value.
571+
template_html = template_html.replace(/\[(\w*)\]/g, function (match, name) {
572+
return Object.prototype.hasOwnProperty.call(oMacros, name) ? oMacros[name] : match;
568573
});
569574
return template_html;
570575
},

0 commit comments

Comments
 (0)