Skip to content

Commit

Permalink
Uppercases the method variable to sanitize the string
Browse files Browse the repository at this point in the history
Summary:This prevents possible developer errors when using 'post' or 'put' instead of 'POST' and 'PUT'.

Fixes: #6855

**Test plan:**

Previously, a `method put must not have a request body` error would be thrown when the method was in lowercase and a request body was indeed included.

With this fix and the following code (note the method name in all lowercase), the request is properly completed.

```javascript
const url = 'http://myurl.com';
const request = new XMLHttpRequest();

request.open('put', url);
request.setRequestHeader("Content-type","application/json");

request.onload = function() {
    console.log('onload');
};

request.onerror = function() {
    console.log('error');
};

request.send(JSON.stringify({ something: 'here' }));
```
Closes #6956

Differential Revision: D3173467

Pulled By: davidaurelio

fb-gh-sync-id: add90e9f31cd4f548547a3f85267a782ae74a89c
fbshipit-source-id: add90e9f31cd4f548547a3f85267a782ae74a89c
  • Loading branch information
dsibiski authored and Facebook Github Bot 4 committed Apr 13, 2016
1 parent 234142c commit 4450d78
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Libraries/Network/XMLHttpRequestBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class XMLHttpRequestBase {
throw new Error('Cannot load an empty url');
}
this._reset();
this._method = method;
this._method = method.toUpperCase();
this._url = url;
this._aborted = false;
this.setReadyState(this.OPENED);
Expand Down

0 comments on commit 4450d78

Please sign in to comment.