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

Fixes invalid regexp scenario #1081

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions frontend/src/components/pages/acls/Acl.List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,16 @@ class AclList extends PageComponent {
</Alert>
: null;

const quickSearchRegExp = new RegExp(uiSettings.aclList.configTable.quickSearch, 'i')

const groups = this.principalGroups.filter(
aclGroup => aclGroup.principalName.match(quickSearchRegExp)
);
let groups = this.principalGroups
try {
const quickSearchRegExp = new RegExp(uiSettings.aclList.configTable.quickSearch, 'i')
groups = groups.filter(
aclGroup => aclGroup.principalName.match(quickSearchRegExp)
);
} catch (e) {
console.warn('Invalid expression')
}

return <>
<AlertDeleteFailed aclFailed={this.aclFailed} onClose={() => {
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/components/pages/admin/Admin.Users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ export class AdminUsers extends Component<{}> {
render() {
if (!api.adminInfo) return DefaultSkeleton;

const quickSearchRegExp = new RegExp(this.quickSearch, 'i')
let users = api.adminInfo.users

const users = this.quickSearch.length > 0 ? api.adminInfo.users.filter(u => u.internalIdentifier.match(quickSearchRegExp) || u.oauthUserId.match(quickSearchRegExp)) : api.adminInfo.users;
try {
const quickSearchRegExp = new RegExp(this.quickSearch, 'i')
users = users.filter(u => u.internalIdentifier.match(quickSearchRegExp) || u.oauthUserId.match(quickSearchRegExp))
} catch (e) {
console.warn('Invalid expression')
}

const table = (
<DataTable<UserDetails>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ export const TopicInput = observer((p: { properties: Property[], connectorType:
if (!allTopics) return [];

if (this.isRegex) {
const regex = new RegExp(String(this.property.value));
return allTopics.filter(t => regex.test(t));
try {
const regex = new RegExp(String(this.property.value));
return allTopics.filter(t => regex.test(t));
} catch (e) {
console.warn('Invalid expression')
}
return allTopics
} else {
const validTopics = String(this.property.value).split(',');
return allTopics.filter(t => validTopics.includes(t));
Expand Down
18 changes: 12 additions & 6 deletions frontend/src/components/pages/consumers/Group.List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,19 @@ class GroupList extends PageComponent {
render() {
if (!api.consumerGroups) return DefaultSkeleton;

const quickSearchRegExp = new RegExp(uiSettings.consumerGroupList.quickSearch, 'i')
let groups = Array.from(api.consumerGroups.values())

try {
const quickSearchRegExp = new RegExp(uiSettings.consumerGroupList.quickSearch, 'i')
groups = groups
.filter(groupDescription =>
groupDescription.groupId.match(quickSearchRegExp) ||
groupDescription.protocol.match(quickSearchRegExp)
);
} catch (e) {
console.warn('Invalid expression')
}

const groups = Array.from(api.consumerGroups.values())
.filter(groupDescription =>
groupDescription.groupId.match(quickSearchRegExp) ||
groupDescription.protocol.match(quickSearchRegExp)
);
const stateGroups = groups.groupInto(g => g.state);

return (
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/components/pages/schemas/Schema.List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ class SchemaList extends PageComponent<{}> {
if (api.schemaOverviewIsConfigured == false) return renderNotConfigured();
if (api.schemaSubjects === undefined) return DefaultSkeleton; // request in progress

const quickSearchRegExp = new RegExp(uiSettings.schemaList.quickSearch, 'i')

const filteredSubjects = api.schemaSubjects
.filter(x => uiSettings.schemaList.showSoftDeleted || (!uiSettings.schemaList.showSoftDeleted && !x.isSoftDeleted))
.filter(x => x.name.toLowerCase().match(quickSearchRegExp));
let filteredSubjects = api.schemaSubjects
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint?


try {
const quickSearchRegExp = new RegExp(uiSettings.schemaList.quickSearch, 'i')
filteredSubjects = filteredSubjects.filter(x => uiSettings.schemaList.showSoftDeleted || (!uiSettings.schemaList.showSoftDeleted && !x.isSoftDeleted))
.filter(x => x.name.toLowerCase().match(quickSearchRegExp));
} catch (e) {
console.warn('Invalid expression')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should handle or rethrow the error or capture the exception. Maybe we should also check that the regexp should run, if there is no uiSettings.schemaList.quickSearch for example?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@malinskibeniamin based on what I found there is no other way to check whether regexp is valid other than trying to compose it and catch with an exception. IF it's valid, we filter on it, if it's not valid, we keep the original array.

}

return (
<PageContent key="b">
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/components/pages/topics/Topic.List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ class TopicList extends PageComponent {
if (uiSettings.topicList.hideInternalTopics) {
topics = topics.filter(x => !x.isInternal && !x.topicName.startsWith('_'));
}
const quickSearchRegExp = new RegExp(uiSettings.topicList.quickSearch.toLowerCase(), 'i')

topics = topics.filter(x => {
return x.topicName.toLowerCase().match(quickSearchRegExp);
});
try {
const quickSearchRegExp = new RegExp(uiSettings.topicList.quickSearch.toLowerCase(), 'i')

topics = topics.filter(x => {
return x.topicName.toLowerCase().match(quickSearchRegExp);
});
} catch (e) {
console.warn('Invalid expression')
}


const partitionCount = topics.sum((x) => x.partitionCount);
Expand Down
Loading