-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
// Replaces all beginning and trailing spaces and quotes. | ||
const regex = /^[" ]+|[" ]+$/g; | ||
tokens.push(str.substring(tokenStart, i).replace(regex, '')); | ||
tokenStart = i + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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
There was a problem hiding this comment.
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
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.