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

Web: create JS version of parsing string with double quotes delimited by commas #41086

Merged
merged 2 commits into from
May 1, 2024

Conversation

kimlisa
Copy link
Contributor

@kimlisa kimlisa commented May 1, 2024

part of https://github.com/gravitational/teleport.e/issues/3933

I needed a way to parse string with quotes delimited by comma "access", "editor", "admin", so i took the backend version of ParseSearchKeywords and turned it into the JS version.

This comment was marked as resolved.

@kimlisa kimlisa added no-changelog Indicates that a PR does not require a changelog entry backport/branch/v15 and removed ui size/md labels May 1, 2024
Comment on lines +53 to +56
// Replaces all beginning and trailing spaces and quotes.
const regex = /^[" ]+|[" ]+$/g;
tokens.push(str.substring(tokenStart, i).replace(regex, ''));
tokenStart = i + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Replaces all beginning and trailing spaces and quotes.
const regex = /^[" ]+|[" ]+$/g;
tokens.push(str.substring(tokenStart, i).replace(regex, ''));
tokenStart = i + 1;
// Replaces all beginning and trailing spaces and quotes.
tokens.push(str.substring(tokenStart, i).trim().replace('"', ''));
tokenStart = i + 1;

can we use trim and then just replace the quotes? would be easier than a regex imo. Up to you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the regex does: only replace quotes from start and end (not in between), and handles spaces before and after quotes

@public-teleport-github-review-bot public-teleport-github-review-bot bot removed the request for review from gzdunek May 1, 2024 15:38
@kimlisa kimlisa enabled auto-merge May 1, 2024 16:59
@kimlisa kimlisa added this pull request to the merge queue May 1, 2024
Merged via the queue into master with commit 00d8add May 1, 2024
39 checks passed
@kimlisa kimlisa deleted the lisa/web-parse-string branch May 1, 2024 17:16
@public-teleport-github-review-bot

@kimlisa See the table below for backport results.

Branch Result
branch/v15 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/branch/v15 no-changelog Indicates that a PR does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants