-
Notifications
You must be signed in to change notification settings - Fork 96
Optimize query parameter key=value parsing #3200
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -72,7 +72,7 @@ final class DialogueFeignClient implements feign.Client { | |||||||||||||||||||||
private static final String REQUEST_URL_PATH_PARAM = "request-url"; | ||||||||||||||||||||||
private static final Splitter PATH_SPLITTER = Splitter.on('/'); | ||||||||||||||||||||||
private static final Splitter QUERY_SPLITTER = Splitter.on('&').omitEmptyStrings(); | ||||||||||||||||||||||
private static final Splitter QUERY_VALUE_SPLITTER = Splitter.on('='); | ||||||||||||||||||||||
private static final char QUERY_KEY_VALUE_SEPARATOR = '='; | ||||||||||||||||||||||
|
||||||||||||||||||||||
private final ConjureRuntime runtime; | ||||||||||||||||||||||
private final Channel channel; | ||||||||||||||||||||||
|
@@ -386,6 +386,7 @@ private final class FeignEndpoint implements Endpoint { | |||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
@Override | ||||||||||||||||||||||
@SuppressWarnings("CyclomaticComplexity") | ||||||||||||||||||||||
public void renderPath(ListMultimap<String, String> params, UrlBuilder url) { | ||||||||||||||||||||||
List<String> requestUrls = params.get(REQUEST_URL_PATH_PARAM); | ||||||||||||||||||||||
Preconditions.checkState( | ||||||||||||||||||||||
|
@@ -417,14 +418,17 @@ public void renderPath(ListMultimap<String, String> params, UrlBuilder url) { | |||||||||||||||||||||
if (queryParamsStart != -1) { | ||||||||||||||||||||||
String querySegments = trailing.substring(queryParamsStart + 1); | ||||||||||||||||||||||
for (String querySegment : QUERY_SPLITTER.split(querySegments)) { | ||||||||||||||||||||||
List<String> keyValuePair = QUERY_VALUE_SPLITTER.splitToList(querySegment); | ||||||||||||||||||||||
if (keyValuePair.size() != 2) { | ||||||||||||||||||||||
int equalsIndex = querySegment.indexOf(QUERY_KEY_VALUE_SEPARATOR); | ||||||||||||||||||||||
if (equalsIndex > 0) { | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||
String key = querySegment.substring(0, equalsIndex); | ||||||||||||||||||||||
String value = querySegment.substring(equalsIndex + 1); | ||||||||||||||||||||||
url.queryParam(urlDecode(key), urlDecode(value)); | ||||||||||||||||||||||
} else { | ||||||||||||||||||||||
Comment on lines
+422
to
+426
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I'd prefer if we wrote this as if-throw to avoid additional nesting in the non-exceptional case. |
||||||||||||||||||||||
throw new SafeIllegalStateException( | ||||||||||||||||||||||
"Expected two parameters", | ||||||||||||||||||||||
SafeArg.of("parameters", keyValuePair.size()), | ||||||||||||||||||||||
UnsafeArg.of("values", keyValuePair)); | ||||||||||||||||||||||
SafeArg.of("parameters", equalsIndex == -1 ? 0 : 1), | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parameter count logic is incorrect. When
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||
UnsafeArg.of("values", querySegment)); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This validation logic is incorrect. It checks for additional '=' characters starting from
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||
url.queryParam(urlDecode(keyValuePair.get(0)), urlDecode(keyValuePair.get(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.
We probably want to ensure that there aren't more than 2 segments.