-
Notifications
You must be signed in to change notification settings - Fork 187
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
[BUG] URL variables are not properly escaped #827
Comments
Is this encoding happening incorrectly in the client? Can you encode before calling a client? Want to try to add a test that reproduces this, and maybe a fix? |
When encoding before calling the OpenSearchClient.get(), the encoded The problem is this line of code: Which calls this method: Line 135 in 3884476
Unfortunately, this encoding isn't configurable by users of OpenSearch client, so I don't have a way to override this behavior. |
Thanks, so it's just a bug where those arguments should not be encoded at all? I would write some tests of the expected behavior and fix it. |
This was the same root cause as #1068, A fix/feature to support this was released as part of v2.13.0. |
What is the bug?
When a GetRequest is referenced in a
GET <index>/_doc/<id>
call, the ID variable gets URL encoded for all special characters other than punctuation. This is causing issue with IDs that are a JSON formatted string. The braces character and quotes character gets encoded, but not the,
or the:
. Here is a sample GET request logged (scrubbed):This would result in a 404 returned by the Java client. When I entered the same request in the OpenSearch dashboard dev console, the same result occurs. However, when I encode the
,
and:
properly in the console request, the document I wanted gets returned.How can one reproduce the bug?
Write a document into the OpenSearch collection with a JSON string as the ID.
Pass in that JSON string in a OpenSearchClient.get() request as the ID.
What is the expected behavior?
The ID gets encoded properly into this request:
What is your host/environment?
AWS Lambda Java 17
Do you have any screenshots?
If applicable, add screenshots to help explain your problem.
Do you have any additional context?
When digging into the codebase, I found that the encoding is done by
org.apache.http.client.utils.URLEncodedUtils.formatSegment
, which encodes only escaping characters that would affect the path. I usedjava.net.URLEncoder.encode
to get the expected behavior, but I'm not sure how it affects other use cases (such as spaces).The text was updated successfully, but these errors were encountered: