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

Problem With Forward Params #9526

Closed
osscontributor opened this issue Dec 29, 2015 · 10 comments
Closed

Problem With Forward Params #9526

osscontributor opened this issue Dec 29, 2015 · 10 comments

Comments

@osscontributor
Copy link
Member

package demo

class DemoController {

    def someAction() {
        forward action: 'someOtherAction', params: params
    }

    def someOtherAction() {
        render "First Name: ${params.firstName}"
    }
}

If I send a request to a url like http://localhost:8080/demo/someAction?firstName=Jeff, the response includes something like First Name: [Jeff, Jeff].

I see the behavior in 3.1.0.RC1 and 3.0.10.

Probably related to the issue at #9525 but I can't tell if that is what is being reported there or not.

@orubel
Copy link

orubel commented Dec 31, 2015

@jeffbrown Thanks for catching this. Thought this was MY ISSUE in my code and was trying over and over to troubleshoot and remove params after forward until I saw bug.

Seeing issue with sending it other ways as well.

forward(uri:params.uri,params:params)

causes same error after multiple forwards. Tried to correct with params.remove but doesn't seem to work...

Here are example of test params coming back after forwarding ONCE(note:batchIncrement->batchInc was incremented one time):

sectionName: Forp
sectionName: Gorp
batchInc: 1
batchInc: 0
controller: section
controller: section
batchLength: 4
batchLength: 4
method: POST
method: POST
format: JSON
format: JSON
action: create
action: create
entryPoint: b0.1
entryPoint: b0.1
encoding: UTF-8
encoding: UTF-8
apiObject: 1
apiObject: 1
contentType: application/json
contentType: application/json
uri: /b0.1/section/create
uri: /b0.1/section/create

So it looks like it is concatenating the params somehow with every forward...

@orubel
Copy link

orubel commented Dec 31, 2015

Ok, after some investigation, I suspect this may be due to DefaultLinkGenerator.groovy ( https://github.com/grails/grails-core/blob/0b1d6a6d02f2217643a69e8314f76078dacbce32/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy ) in that it doesn't take into consideration forwarding multiple times; it looks like this would concatenate them when URLEncoding them back in and if you forward multiple times, the params just keep getting concatenated. Does this sound correct? Am I reading this wrong

@orubel
Copy link

orubel commented Jan 5, 2016

This seems to be same issue as #9531

@osscontributor
Copy link
Member Author

This seems to be same issue as #9531

@orubel As far as I can tell, that looks like a different problem.

@graemerocher
Copy link
Member

I don't think this is a bug, this is the way servlet containers work. If you forward the request the original request parameters are available to the receiving controller/action. So if you do:

   forward action: 'someOtherAction', params: params

You are essentially duplicating what the container already does for you, hence why you get 2 of everything (the original params and the new ones that have the same name as the originals). If you simply write:

   forward action: 'someOtherAction'

This will give you the desired behaviour

@orubel
Copy link

orubel commented Jan 5, 2016

keen thanks. :)

@orubel
Copy link

orubel commented Jan 5, 2016

@graemerocher Actually I would argue this IS A BUG in the fact that above, you can see that it isn't forwarding the params changes. I just went ahead and tested again and confirmed. If you concatenate prior to a forward, that change won't show... at least it isn't showing when I make changes at the handlerInterceptor level.

And since a forward can happen then as well and params changes can happen that late prior to forward, it makes sense that they should be able to get in and be seen in the forward.

If you look at the data above, you will see the first set of params sent back that are concatenating don't have the changes made to the params.

Am I doing something wrong?

@osscontributor
Copy link
Member Author

I think this is a case where the way to make it work would be to mutate the original params Map. If you would like to discuss further, the mailing list is a better place to do that than the issue tracker.

Thanks for the feedback.

@orubel
Copy link

orubel commented Jan 5, 2016

Thanks. Posted question in 'questions' on slack. Much appreciated.

@purpleraven
Copy link
Contributor

I got the problem, during migration from grails 2
Looks like not expect behavior. I hope, it will be fixed in future

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

No branches or pull requests

4 participants