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

Encoding of body_params vs param/params #1192

Closed
patrickbkr opened this issue Jun 20, 2016 · 3 comments
Closed

Encoding of body_params vs param/params #1192

patrickbkr opened this issue Jun 20, 2016 · 3 comments
Labels

Comments

@patrickbkr
Copy link
Contributor

  • Dancer2 v0.200001

  • config.yml has charset: "UTF-8" set.

  • When doing

    my @params = (Empfänger => '毛泽东');
    $user_agent->post(
        $url,
        'Content-type' => "application/x-www-form-urlencoded; charset='utf8'",
        Content      => [ map { Encode::encode_utf8( $_ ) } @params ],
    );
    
  • params returns

    { Empfänger => '毛泽东' }
    
  • and body_parameters returns

    { Empfänger => '�泽�' }
    
  • When doing a map { Encode::decode( "utf-8", $_) } on that I get the decoded version.

I tracked params down to Request.pm:312: $self->_params which is initialized in line 460 with $self->_body_params wich does a _decode in line 125.

And body_parameters in Request.pm:368: return $self->env->{'plack.request.body'}.

I am rather unskilled with providing good information. So if I should provide more (which?) information, please say so!

@patrickbkr patrickbkr changed the title body_params vs param/params Encoding of body_params vs param/params Jun 20, 2016
@SysPete
Copy link
Member

SysPete commented Jul 21, 2016

Looking at code and tests (t/dsl/parameters.t) this actually looks intentional though I have not (yet) found anything in the docs that mentions this difference.

@PerlDancer (especially @xsawyerx) I've been hunting through the various issues and PR #988 but I can't find any discussion or explanation for this particular difference between params and parameters. Can anyone help enlighten us?

SysPete added a commit that referenced this issue Jul 22, 2016
See issue #1192.

@veryrusty said: I suspect the param encoding change was a regression.
When the request object became a subclass of Plack::Request, we used the
existing body_params methods from Plack::Request.  They do not decode
params. Whereas Dancer(2) always has decoded params.  Decoding
*is* the correct thing to be doing (IMHO).
@SysPete
Copy link
Member

SysPete commented Jul 22, 2016

@PatZim many thanks for spending the time to submit this detailed issue. I've created PR #1219 which addresses it.

SysPete added a commit that referenced this issue Jul 29, 2016
See issue #1192.

@veryrusty said: I suspect the param encoding change was a regression.
When the request object became a subclass of Plack::Request, we used the
existing body_params methods from Plack::Request.  They do not decode
params. Whereas Dancer(2) always has decoded params.  Decoding
*is* the correct thing to be doing (IMHO).
@racke racke added the UTF-8 label Aug 2, 2016
cromedome pushed a commit that referenced this issue Aug 12, 2016
See issue #1192.

@veryrusty said: I suspect the param encoding change was a regression.
When the request object became a subclass of Plack::Request, we used the
existing body_params methods from Plack::Request.  They do not decode
params. Whereas Dancer(2) always has decoded params.  Decoding
*is* the correct thing to be doing (IMHO).
cromedome added a commit that referenced this issue Aug 12, 2016
@cromedome
Copy link
Contributor

Fixed in 1d62e51. Closing.

cromedome added a commit that referenced this issue Aug 13, 2016
    [ BUG FIXES ]
    * Fix memory leak in plugins. (Sawyer X)
    * GH #1180, #1220: Revert (most of) GH #1120. Change back to using
      MooX::Types::MooseLike until issues around Type::Tiny are resolved.
      Peter (@SysPete) Mottram
    * GH #1192: Decode body|query|request_parameters (Peter Mottram)
    * GH #1224: Plugins defined with :PluginKeyword attribute are now
      exported. (Yanick Champoux)
    * GH #1226: Plugins can now call the DSL of the app via $self->dsl
      (Sawyer X)

    [ ENHANCEMENTS ]
    * PR #1223: Add YAML::XS to Recommends (Peter Mottram)
    * PR #1117: If installed, use HTTP::XSCookies and all cookie operations
      will be faster (Peter Mottram)
    * PR #1228: Allow register_plugin() to pass @_ properly (Sawyer X)
    * PR #1231: Plugins can now call the syntax of plugins they loaded
      (Sawyer X)

    [ DOCUMENTATION ]
    * PR #1151: Note that config is immutable after first read (Peter Mottram)
    * PR #1222: Update list of files generated by `dancer2 -a`, make name of
      sample app consistent (Daniel Perrett)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants