Skip to content

Invalid encoding of %20 char sequence in $.ajax post, put body #4119

@ermouth

Description

@ermouth

Description

Seems that jQuery 3 replaces %20 char sequence to + in a request body during PUT and POST. A request like

$.ajax({
  method: 'put', 
  url: '/test/doc', 
  dataType: 'json',
  headers: {'content-type':'application/json'},
  data: JSON.stringify({val:'%20'})
})

actually sends {"val":"+"} in 3.2.1 and 3.3.1, both with Migration tools.

jQuery however 2.x behaves correctly.

Update. Seems the reason is this block https://github.com/jquery/jquery/blob/master/src/ajax.js#L617-L621. It assumes s.contentType is the only source of Content-Type header, but there can be s.headers['content-type'], which later (https://github.com/jquery/jquery/blob/master/src/ajax.js#L648-L650) overrides s.contentType value.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions