Skip to content

Commit 55969f9

Browse files
Merge pull request #8026 from rabbitmq/mergify/bp/v3.11.x/pr-8023
Management UI: handle invalid regular expressions in filters when switching tabs (backport #8010) (backport #8023)
2 parents 2c5c6f6 + 7a46b30 commit 55969f9

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

deps/rabbitmq_management/priv/www/js/global.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,7 @@ var HELP = {
490490

491491
'filter-regex' :
492492
'Whether to enable regular expression matching. Both string literals \
493-
and regular expressions are matched in a case-insensitive manner.<br/><br/> \
494-
(<a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions" target="_blank">Regular expression reference</a>)',
493+
and regular expressions are matched in a case-insensitive manner.<br/><br/>',
495494

496495
'consumer-active' :
497496
'Whether the consumer is active or not, i.e. whether the consumer can get messages from the queue. \
@@ -501,7 +500,7 @@ var HELP = {
501500
(<a href="https://www.rabbitmq.com/consumers.html#active-consumer" target="_blank">Documentation</a>)',
502501

503502
'consumer-owner' :
504-
'<a href="https://www.rabbitmq.com/consumers.html">AMQP consumers</a> belong to an AMQP channel, \
503+
'<a href="https://www.rabbitmq.com/consumers.html">AMQP 0-9-1 consumers</a> belong to a channel, \
505504
and <a href="https://www.rabbitmq.com/stream.html">stream consumers</a> belong to a stream connection.',
506505

507506
'plugins' :

deps/rabbitmq_management/priv/www/js/main.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ function set_timer_interval(interval) {
253253
}
254254

255255
function reset_timer() {
256-
clearInterval(timer);
256+
if (timer != null) {
257+
clearInterval(timer);
258+
}
257259
if (timer_interval != null) {
258260
timer = setInterval(partial_update, timer_interval);
259261
}
@@ -733,13 +735,31 @@ function postprocess() {
733735
update_multifields();
734736
}
735737

738+
function is_valid_regexp(value) {
739+
try {
740+
var _ = new RegExp(value, 'i');
741+
return true;
742+
} catch (e) {
743+
return false;
744+
}
745+
}
746+
736747
function url_pagination_template_context(template, context, defaultPage, defaultPageSize){
737748
var page_number_request = fmt_page_number_request(context, defaultPage);
738749
var page_size = fmt_page_size_request(context, defaultPageSize);
739750
var name_request = fmt_filter_name_request(context, "");
740751
var use_regex = fmt_regex_request(context, "") == "checked";
741752
if (use_regex) {
742-
name_request = esc(name_request);
753+
// rabbitmq/rabbitmq-server#8008: if the expression cannot be compiled to a reg exp,
754+
// assume a regular text filter
755+
var valid_regexp = is_valid_regexp(name_request);
756+
if (!valid_regexp) {
757+
show_popup('warn', fmt_escape_html(`Filter expression '${name_request}' is not a valid regular expression, will perform a regular text query`));
758+
use_regex = false;
759+
}
760+
if (use_regex && valid_regexp) {
761+
name_request = esc(name_request);
762+
}
743763
}
744764
return '/' + template +
745765
'?page=' + page_number_request +

0 commit comments

Comments
 (0)