Properly parse URIs for invalid terms

This commit is contained in:
Rafael 2022-01-26 09:27:59 -03:00 committed by Thomas Zarebczan
parent e4d5d69524
commit 44213fbad2

View file

@ -14,6 +14,7 @@ import TextareaSuggestionsItem from 'component/textareaSuggestionsItem';
import TextField from '@mui/material/TextField'; import TextField from '@mui/material/TextField';
import useLighthouse from 'effects/use-lighthouse'; import useLighthouse from 'effects/use-lighthouse';
import useThrottle from 'effects/use-throttle'; import useThrottle from 'effects/use-throttle';
import { parseURI } from 'util/lbryURI';
const SUGGESTION_REGEX = new RegExp( const SUGGESTION_REGEX = new RegExp(
'((?:^| |\n)@[^\\s=&#$@%?:;/\\"<>%{}|^~[]*(?::[\\w]+)?)|((?:^| |\n):[\\w+-]*:?)', '((?:^| |\n)@[^\\s=&#$@%?:;/\\"<>%{}|^~[]*(?::[\\w]+)?)|((?:^| |\n):[\\w+-]*:?)',
@ -102,7 +103,15 @@ export default function TextareaWithSuggestions(props: Props) {
const suggestionTerm = suggestionValue && suggestionValue.term; const suggestionTerm = suggestionValue && suggestionValue.term;
const isEmote = suggestionValue && suggestionValue.isEmote; const isEmote = suggestionValue && suggestionValue.isEmote;
const isMention = suggestionValue && !suggestionValue.isEmote; const isMention = suggestionValue && !suggestionValue.isEmote;
const invalidTerm = suggestionTerm && isMention && suggestionTerm.charAt(1) === ':';
let invalidTerm = suggestionTerm && isMention && suggestionTerm.charAt(1) === ':';
if (isMention && suggestionTerm) {
try {
parseURI(suggestionTerm);
} catch (error) {
invalidTerm = true;
}
}
const additionalOptions = { isBackgroundSearch: false, [SEARCH_OPTIONS.CLAIM_TYPE]: SEARCH_OPTIONS.INCLUDE_CHANNELS }; const additionalOptions = { isBackgroundSearch: false, [SEARCH_OPTIONS.CLAIM_TYPE]: SEARCH_OPTIONS.INCLUDE_CHANNELS };
const { results, loading } = useLighthouse(debouncedTerm, showMature, SEARCH_SIZE, additionalOptions, 0); const { results, loading } = useLighthouse(debouncedTerm, showMature, SEARCH_SIZE, additionalOptions, 0);