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

JS-Rewrite: Preserve query string rewrite when the request contains a body #3172

Merged
merged 1 commit into from
Sep 24, 2020

Conversation

jjrodrig
Copy link
Contributor

Overview

During the porting of rewrite_js.js tests into the elixir test suite I've found an erroneous behavior in the JS-rewrite functionality.

When a rewritten request contains a BODY (POST/PUT) and the rewrite rule rewrites the query string, this query string is ignored in the final request. The following case illustrates this issue.

1 - Create a design document with a rule that rewrites the query string, like this one:

 {
      "_id": "_design/n", 
      "rewrites": "function (r) { return {path: '../../_changes', query: {'filter': '_doc_ids'}};};"
    }

any request should be rewritten to _changes?filter=_docs_ids

curl -XPOST -u adm:pass -H "Content-type: application/json" \
   -d '{"_id": "_design/n", "rewrites": "function (r) { return {path: '\''../../_changes'\'', query: {'\''filter'\'': '\''_doc_ids'\''}};};"}' \
   https://127.0.0.1:15984/test

2 - Create a couple of docs

curl -XPUT -u adm:pass -H "Content-type: application/json" -d '{}' https://127.0.0.1:15984/test/1 
curl -XPUT -u adm:pass -H "Content-type: application/json" -d '{}' https://127.0.0.1:15984/test/2

3 - Perform a POST request to be rewritten

 curl -XPOST -u adm:pass -H "Content-type: application/json" \
    -d '{"doc_ids": ["2"]}' \
     https://127.0.0.1:15984/test/_design/n/_rewrite

The expected result for this case is to have only the change for the doc with id 2 in the response, but the full change list is returned. The filter=_doc_ids is ignored after the rewritten.

This PR changes this behavior and the query string is preserved, so the result for the previous case is the excepted one returning only the change for the doc with id 2.

Testing recommendations

The previous test case has been added to rewrite_js.js tests

 make javascript suites="rewrite_js, rewrite"

Related Issues or Pull Requests

This issue #1612 and the companion PR #1620 are related to this issue

Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants