Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search crash Issue #723

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/renderer/components/database-list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useAppSelector } from '../hooks/redux';
import { Database } from '../reducers/databases';
import { DbTable } from '../../common/types/database';
import type { ActionType, ObjectType } from '../reducers/sqlscripts';
import { RegexString } from '../utils/search';

const MENU_CTX_ID = 'CONTEXT_MENU_DATABASE_LIST_ITEM';

Expand Down Expand Up @@ -45,7 +46,7 @@ const filterItems: <T extends { schema?: string; name: string }>(
filterInput: string,
items: T[],
) => T[] = (filterInput, items) => {
const regex = RegExp(filterInput, 'i');
const regex = RegexString(filterInput);
return items.filter((item) => regex.test(`${item.schema ? `${item.schema}.` : ''}${item.name}`));
};

Expand Down
3 changes: 2 additions & 1 deletion src/renderer/containers/query-browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { Database } from '../reducers/databases';
import { DbTable } from '../../common/types/database';
import QueryTabs from '../components/query-tabs';
import type { ActionType, ObjectType } from '../reducers/sqlscripts';
import { RegexString } from '../utils/search';

require('./query-browser.css');
require('../components/react-resizable.css');
Expand Down Expand Up @@ -404,7 +405,7 @@ const QueryBrowserContainer: FC = () => {
]
: [];

const regex = RegExp(filter, 'i');
const regex = RegexString(filter);
const filteredDatabases = databases.items.filter((db) => regex.test(db.name));

const selectedDb = databases.diagramDatabase;
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/containers/server-management.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import SettingsModalForm from '../components/settings-modal-form';
import ServerFilter from '../components/server-filter';
import Message from '../components/message';
import { Server } from '../../common/types/server';
import { RegexString } from '../utils/search';

const BREADCRUMB = [{ icon: 'server', label: 'servers' }];

function filterServers(name: string, servers: Server[]): Server[] {
const regex = RegExp(name, 'i');
const regex = RegexString(name);
return servers.filter((srv) => regex.test(srv.name));
}

Expand Down
3 changes: 3 additions & 0 deletions src/renderer/utils/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function RegexString(name: string): RegExp {
return new RegExp(name.replace(/[^a-z0-9]/gi, ''), 'i');
}