subs: Fix incorrect use of RegExp in stream filtering.

When filtering streams, we were incorrectly treating the regexp input
provided by the user as a regular expression, meaning that terms like
`c++` would trigger errors because they are invalid regular expression
syntax.  We fix this by replacing RegExp with a simple IndexOf check.

Node test added by tabbott.

Fixes #3559.
This commit is contained in:
khantaalaman
2017-02-04 17:32:31 +05:30
committed by Tim Abbott
parent b82104a769
commit c3fd0d4e0c
2 changed files with 17 additions and 1 deletions

View File

@@ -41,10 +41,16 @@ i18n.init({
name: 'Pomona',
stream_id: 3,
};
var cpp = {
subscribed: true,
name: 'C++',
stream_id: 4,
};
var elem_1 = $(global.render_template("subscription", denmark));
var elem_2 = $(global.render_template("subscription", poland));
var elem_3 = $(global.render_template("subscription", pomona));
var elem_4 = $(global.render_template("subscription", cpp));
$("body").empty();
$("body").append('<div id="subscriptions_table"></div>');
@@ -54,6 +60,7 @@ i18n.init({
stream_data.add_sub("Denmark", denmark);
stream_data.add_sub("Poland", poland);
stream_data.add_sub("Pomona", pomona);
stream_data.add_sub("C++", cpp);
streams_list.append(elem_1);
streams_list.append(elem_2);
@@ -82,6 +89,13 @@ i18n.init({
assert(!elem_2.hasClass("notdisplayed"));
assert(!elem_3.hasClass("notdisplayed"));
// Search handles unusual characters like C++
subs.filter_table({input: "c++", subscribed_only: false});
assert(elem_1.hasClass("notdisplayed"));
assert(elem_2.hasClass("notdisplayed"));
assert(elem_3.hasClass("notdisplayed"));
assert(!elem_4.hasClass("notdisplayed"));
// Search subscribed streams only
subs.filter_table({input: "d", subscribed_only: true});
assert(elem_1.hasClass("notdisplayed"));