Skip to content

Commit

Permalink
FIX: Stop autocomplete for invalid usernames. (#7005)
Browse files Browse the repository at this point in the history
  • Loading branch information
udan11 authored and SamSaffron committed Feb 15, 2019
1 parent f8b70f4 commit a423a93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/assets/javascripts/discourse/lib/user-search.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ export default function userSearch(options) {
topicId = options.topicId,
group = options.group;

if (/[^\w.-]/.test(term)) {
term = "";
}

if (oldSearch) {
oldSearch.abort();
oldSearch = null;
Expand Down
6 changes: 6 additions & 0 deletions test/javascripts/lib/user-search-test.js.es6
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import userSearch from "discourse/lib/user-search";
import { CANCELLED_STATUS } from "discourse/lib/autocomplete";

QUnit.module("lib:user-search", {
beforeEach() {
Expand Down Expand Up @@ -71,3 +72,8 @@ QUnit.test("it strips @ from the beginning", async assert => {
let results = await userSearch({ term: "@Team" });
assert.equal(results[results.length - 1]["name"], "team");
});

QUnit.test("it does not search for invalid usernames", async assert => {
let results = await userSearch({ term: "foo, " });
assert.equal(results, CANCELLED_STATUS);
});

1 comment on commit a423a93

@SamSaffron
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.