FIX: Stop autocomplete for invalid usernames. (#7005)

This commit is contained in:
Dan Ungureanu 2019-02-15 02:29:26 +02:00 committed by Sam
parent f8b70f4ca3
commit a423a9383f
2 changed files with 10 additions and 0 deletions

View File

@ -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;

View File

@ -1,4 +1,5 @@
import userSearch from "discourse/lib/user-search";
import { CANCELLED_STATUS } from "discourse/lib/autocomplete";
QUnit.module("lib:user-search", {
beforeEach() {
@ -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);
});