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

Optimize the regex parser for InvalidResponse #1034

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

@Slf4j
public class InvalidResponse extends RfsException {
private static final Pattern UNKNOWN_SETTING = Pattern.compile("unknown setting \\[(.+?)\\].+");
private static final Pattern UNKNOWN_SETTING = Pattern.compile("unknown setting \\[([a-zA-Z0-9_.-]+)\\].+");
Copy link
Member

Choose a reason for hiding this comment

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

Would the issue also be resolved by changing .+? -> .+

Copy link
Member Author

@peternied peternied Sep 30, 2024

Choose a reason for hiding this comment

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

Yes, but that expression wouldn't be correct since it could match the closing bracket or a host of invalid characters that opensearch would never use in a setting name.

  • ✔️ unknown setting [foo.bar] other stuff -> foo.bar
  • unknown setting [foo.bar] other stuff ] -> foo.bar] other stuff

Copy link
Member

@AndreKurait AndreKurait Sep 30, 2024

Choose a reason for hiding this comment

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

I see.. the issue is that ] shouldn't be a matching character in the inner match.

"unknown setting \\[([^\\]\n]+?)\\].+" this would be the most similar to the original logic that doesn't have the bug

This change seems safe to set the characters inside the [] to those in this PR

private static final ObjectMapper objectMapper = new ObjectMapper();
private final transient HttpResponse response;

Expand Down