Skip to content

querystring.parse decodes incorrect in a specific case #13773

Description

@zkd8907
  • Version: 8.0.0/8.1.2
  • Platform: Windows 10 x64/Linux x64

At Node 7.* or before, the result of require('querystring').parse('a=%20+&') is { a: ' ' }. However, at Node 8.0.0 or 8.1.2, the result of require('querystring').parse('a=%20+&') is { a: '%20 ' }. %20 doesn't decode when it is before +.

Activity

  1. added
    querystringIssues and PRs related to the built-in querystring module.
    zlibIssues and PRs related to the zlib module and its compression dependencies.
    and removed
    zlibIssues and PRs related to the zlib module and its compression dependencies.
    on Jun 19, 2017
  2. targos commented on Jun 19, 2017

    @targos
    Member

    That behavior changed in #11234

    /cc @mscdex

  3. TimothyGu commented on Jun 19, 2017

    @TimothyGu
    Member

    Aside from the issue, it is generally recommended that you use the new URLSearchParams class that parses query strings the exact same way browsers do, which is also faster than querystring module in almost all cases.

  4. jsilveira commented on Jul 9, 2017

    @jsilveira

    After 5 hours of struggling with a an intermittent issue in the encoding of some of the POSTs received from our website, we tracked down the issue to this change in handling trailing spaces. The "random" nature of the issue was caused by the fact that some people submitted the form input with a trailing space.

    So, is this a bug or an expected "changed behaviour" ???

  5. TimothyGu commented on Jul 10, 2017

    @TimothyGu
    Member

    There are a lot more problematic cases

    // str    v8.x     v6.x         expected
    'af+'     {}       {}            { 'af ': '' }
    'af+&'    {}       { 'af ': '' } { 'af ': '' }     REGRESSION
    '%20+'    {}       {}            { '  ': '' }
    '%20+&'   {}       { '  ': '' }  { '  ': '' }      REGRESSION
    '+'       {}       {}            { ' ': '' }
    '+&'      {}       { ' ': '' }   { ' ': '' }       REGRESSION
  6. TimothyGu commented on Jul 10, 2017

    @TimothyGu
    Member

    @jsilveira It is a bug.

  7. added a commit that references this issue on Jul 10, 2017
  8. added a commit that references this issue on Jul 19, 2017
  9. added a commit that references this issue on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.querystringIssues and PRs related to the built-in querystring module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions