mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-30 10:36:35 +02:00
Desktop: Fixes #5380: Prevent it from crashing with too long search queries
This commit is contained in:
parent
d6da4299ad
commit
4c72de8bd8
@ -1,6 +1,11 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import Logger from '@joplin/lib/Logger';
|
||||
import { SearchMarkers } from './useSearchMarkers';
|
||||
|
||||
const logger = Logger.create('useNoteSearchBar');
|
||||
|
||||
const queryMaxLength = 1000;
|
||||
|
||||
interface LocalSearch {
|
||||
query: string;
|
||||
selectedIndex: number;
|
||||
@ -24,6 +29,14 @@ export default function useNoteSearchBar() {
|
||||
const [localSearch, setLocalSearch] = useState<LocalSearch>(defaultLocalSearch());
|
||||
|
||||
const onChange = useCallback((query: string) => {
|
||||
// A query that's too long would make CodeMirror throw an exception
|
||||
// which would crash the app.
|
||||
// https://github.com/laurent22/joplin/issues/5380
|
||||
if (query.length > queryMaxLength) {
|
||||
logger.warn(`Query is longer than ${queryMaxLength} characters - it is going to be trimmed`);
|
||||
query = query.substr(0, queryMaxLength);
|
||||
}
|
||||
|
||||
setLocalSearch((prev: LocalSearch) => {
|
||||
return {
|
||||
query: query,
|
||||
|
Loading…
Reference in New Issue
Block a user