FIX: Stop autocomplete for invalid usernames. (#7005)
This commit is contained in:
parent
f8b70f4ca3
commit
a423a9383f
|
@ -121,6 +121,10 @@ export default function userSearch(options) {
|
||||||
topicId = options.topicId,
|
topicId = options.topicId,
|
||||||
group = options.group;
|
group = options.group;
|
||||||
|
|
||||||
|
if (/[^\w.-]/.test(term)) {
|
||||||
|
term = "";
|
||||||
|
}
|
||||||
|
|
||||||
if (oldSearch) {
|
if (oldSearch) {
|
||||||
oldSearch.abort();
|
oldSearch.abort();
|
||||||
oldSearch = null;
|
oldSearch = null;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import userSearch from "discourse/lib/user-search";
|
import userSearch from "discourse/lib/user-search";
|
||||||
|
import { CANCELLED_STATUS } from "discourse/lib/autocomplete";
|
||||||
|
|
||||||
QUnit.module("lib:user-search", {
|
QUnit.module("lib:user-search", {
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
|
@ -71,3 +72,8 @@ QUnit.test("it strips @ from the beginning", async assert => {
|
||||||
let results = await userSearch({ term: "@Team" });
|
let results = await userSearch({ term: "@Team" });
|
||||||
assert.equal(results[results.length - 1]["name"], "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);
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue