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

Using "+" as a filter is breaking the table view #5387

Closed
Weiko opened this issue May 13, 2024 · 3 comments
Closed

Using "+" as a filter is breaking the table view #5387

Weiko opened this issue May 13, 2024 · 3 comments
Labels
good first issue Good for newcomers type: bug Something isn't working

Comments

@Weiko
Copy link
Member

Weiko commented May 13, 2024

Bug Description

Special characters such as "+" have special meanings in Regex expressions. Using those in a filter breaks the filtering.

Screenshot 2024-05-13 at 17 05 23

Expected behavior

Should filter with existing records regardless of the usage of special characters

Technical inputs

Check isMatchingStringFilter.

@Weiko Weiko added the type: bug Something isn't working label May 13, 2024
Copy link

greptile-apps bot commented May 13, 2024

Disclaimer: This comment was automatically generated with AI. It can give some useful hints as to where to look for, but sometimes it can also give very inaccurate answers so takes this with a pinch of salt :).
To address the issue with special characters such as '+' breaking the table view when used as a filter, you'll need to modify the isMatchingStringFilter function in /packages/twenty-front/src/modules/object-record/record-filter/utils/isMatchingStringFilter.ts. Specifically, for the like and ilike cases, where the input string is converted into a regex pattern, you should escape special regex characters to ensure they are treated as literals. Here's a suggested change for the like and ilike cases: javascript case stringFilter.like !== undefined: { const escapedPattern = stringFilter.like.replace(/[.*+?^${}()|[\]\]/g, '\\$&'); // Escapes special characters const regexPattern = escapedPattern.replace(/%/g, '.*'); const regexCaseSensitive = new RegExp(`^${regexPattern}$`); return regexCaseSensitive.test(value); } case stringFilter.ilike !== undefined: { const escapedPattern = stringFilter.ilike.replace(/[.*+?^${}()|[\]\]/g, '\\$&'); // Escapes special characters const regexPattern = escapedPattern.replace(/%/g, '.*'); const regexCaseInsensitive = new RegExp(`^${regexPattern}$`, 'i'); return regexCaseInsensitive.test(value); } This change adds a step to escape special regex characters in the like and ilike string filters before converting the '%' wildcard characters into '.*' for regex matching. This should allow special characters such as '+' to be used in filters without breaking the table view.

References

/packages/twenty-front/src/modules/object-record/record-filter/utils/isMatchingStringFilter.ts

Ask Greptile

@FelixMalfait FelixMalfait added the good first issue Good for newcomers label May 16, 2024
@suman-somu
Copy link
Contributor

suman-somu commented May 29, 2024

It didn't got error but unexpected behaviour.
Screencast from 2024-05-29 18-08-31.webm

Edit: It's working now without any change. idk why it was not working before.
Screencast from 2024-05-29 21-03-44.webm

@FelixMalfait
Copy link
Member

Thanks @suman-somu! I'm also unable to reproduce the issue so I will close this, it has probably been fixed...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers type: bug Something isn't working
Projects
Status: ✅ Done
Development

No branches or pull requests

4 participants
@Weiko @FelixMalfait @suman-somu and others