From 5f01a1ba966de2f1d2bd41b855c4bbba957d6e8c Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 11 May 2019 09:18:36 -0700 Subject: [PATCH] fix: don't autosuggest when text ends with punctuation (#1207) --- src/routes/_store/computations/autosuggestComputations.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/routes/_store/computations/autosuggestComputations.js b/src/routes/_store/computations/autosuggestComputations.js index bbe4ff2..2915ecf 100644 --- a/src/routes/_store/computations/autosuggestComputations.js +++ b/src/routes/_store/computations/autosuggestComputations.js @@ -1,8 +1,11 @@ import { get } from '../../_utils/lodash-lite' const MIN_PREFIX_LENGTH = 2 -const ACCOUNT_SEARCH_REGEX = new RegExp(`(?:\\s|^)(@\\S{${MIN_PREFIX_LENGTH},})$`) -const EMOJI_SEARCH_REGEX = new RegExp(`(?:\\s|^)(:[^:]{${MIN_PREFIX_LENGTH},})$`) +// Technically mastodon accounts allow dots, but it would be weird to do an autosuggest search if it ends with a dot. +// Also this is rare. https://github.com/tootsuite/mastodon/pull/6844 +const VALID_ACCOUNT_AND_EMOJI_CHAR = '\\w' +const ACCOUNT_SEARCH_REGEX = new RegExp(`(?:\\s|^)(@${VALID_ACCOUNT_AND_EMOJI_CHAR}{${MIN_PREFIX_LENGTH},})$`) +const EMOJI_SEARCH_REGEX = new RegExp(`(?:\\s|^)(:${VALID_ACCOUNT_AND_EMOJI_CHAR}{${MIN_PREFIX_LENGTH},})$`) function computeForAutosuggest (store, key, defaultValue) { store.compute(key,