fixes issue #1: slashes in IDs not encoded. #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was a moderately complicated fix. The old CouchDB wiki has this to say about slashes in document IDs:
(https://wiki.apache.org/couchdb/HTTP_Document_API#line-75)
I initially modified
couchdb.go
to break up the document ID on slash characters and reassemble it with%2F
separators, with a special case for IDs that start with_design
, where I prefixed_design/
and assembled the rest of the ID with escaped slashes. Here are some examples of the transformed IDs:I added new unit tests to
couchdb_test.go
with handlers that responded to the escaped document IDs and found that these tests failed. After some investigation, I found issue #5684 in the golang repo, which was filed becauseurl.URL
was decoding escape sequences in URL paths. My encoding code converted slashes to %2F buturl.URL
converted them back to slashes, which caused the test to fail.The documentation for
url.URL
contained a workaround for this issue: theOpaque
field of aURL
struct can be set with the value of the encoded URL path, and that encoded value will be used inhttp.Request
as the request path. Unfortunately, this involved replacing the call tohttp.NewRequest
in thenewRequest
function with code that constructs aRequest
structure manually. This is the part of the PR that should be reviewed most strictly to make sure I didn't inadvertently miss anything in the request construction. All the unit tests, including my new ones that test getting document IDs containing slashes, are passing.Let me know what you think or if there is anything I can do to improve this code.