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

fix ios formdata boundary include slash #11342

Closed
wants to merge 4 commits into from
Closed

fix ios formdata boundary include slash #11342

wants to merge 4 commits into from

Conversation

li-yechao
Copy link

@li-yechao li-yechao commented Dec 7, 2016

some server not work when upload a file with FromData in ios.
the reason is that there is a slash in boundary, like:

multipart/form-data; boundary=b/QeEbFgqK9PCZo4T/eXv7f.T74SHd5MxCZ846AsTz-yNV0xrRR_Zks4fkNMCzJck9ZE8o

// koa request.js (line 548)
  is(types) {
    if (!types) return typeis(this.req);
    if (!Array.isArray(types)) types = [].slice.call(arguments);
    return typeis(this.req, types);
  }

// type-is index.js (line 237)
function normalizeType (value) {
  // parse the type
  var type = typer.parse(value)

  // remove the parameters
  type.parameters = undefined

  // reformat it
  return typer.format(type)
}

// media-typer
var paramRegExp = /; *([!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) *= *("(?:[ !\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u0020-\u007e])*"|[!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) */g;

thanks for @dougwilson 's answer.

The / is an illegal character for Content-Type, which is what this module parses. The boundary parameter value needs to be quoted if it contains a / character, for example:

multipart/form-data; boundary="b/QeEbFgqK9PCZo4T/eXv7f.T74SHd5MxCZ846AsTz-yNV0xrRR_Zks4fkNMCzJck9ZE8o"

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @javache and @LeoNatan to be potential reviewers.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact cla@fb.com if you have any questions.

@javache
Copy link
Member

javache commented Dec 7, 2016

That will just break #7564 again. Can you instead change the dictionary where we generate the boundary from?

@javache
Copy link
Member

javache commented Dec 7, 2016

const char *boundaryChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_./";

@li-yechao
Copy link
Author

remove slash from the dictionary of generate boundary

@javache
Copy link
Member

javache commented Dec 8, 2016

@facebook-github-bot shipit

@ivpusic
Copy link

ivpusic commented Dec 11, 2016

I have the same issue. Currently https://golang.org/pkg/mime/#ParseMediaType returns error, because of "/". This is fixing the problem for me.

@jaggerwang
Copy link

Same problem, take me a few days to figure this out!!! Before update RN to 0.39, fetch works fine.

@javache
Copy link
Member

javache commented Dec 12, 2016

@unordered Can you sign the CLA so I can pull this?

@li-yechao
Copy link
Author

@javache ok

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 13, 2016
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@facebook-github-bot facebook-github-bot added GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: review-needed labels Dec 14, 2016
@facebook-github-bot
Copy link
Contributor

@javache has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@emadicio
Copy link

Thanks, finally fixed this issue for me!

@emadicio emadicio mentioned this pull request Dec 20, 2016
DanielMSchmidt pushed a commit to DanielMSchmidt/react-native that referenced this pull request Jan 4, 2017
Summary:
some server not work when upload a file with FromData in ios.
the reason is that there is a slash in boundary, like:
```
multipart/form-data; boundary=b/QeEbFgqK9PCZo4T/eXv7f.T74SHd5MxCZ846AsTz-yNV0xrRR_Zks4fkNMCzJck9ZE8o

// koa request.js (line 548)
  is(types) {
    if (!types) return typeis(this.req);
    if (!Array.isArray(types)) types = [].slice.call(arguments);
    return typeis(this.req, types);
  }

// type-is index.js (line 237)
function normalizeType (value) {
  // parse the type
  var type = typer.parse(value)

  // remove the parameters
  type.parameters = undefined

  // reformat it
  return typer.format(type)
}

// media-typer
var paramRegExp = /; *([!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) *= *("(?:[ !\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u0020-\u007e])*"|[!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) */g;
```

thanks for dougwilson 's [answer](jshttp/media-typer#5).
> The / is an illegal character for Content-Type, which is what this module parses
Closes facebook#11342

Differential Revision: D4326750

Pulled By: javache

fbshipit-source-id: b1c78a335c95a5c223537545d87beaffe15d673d
gre pushed a commit to gre/react-native that referenced this pull request Jan 10, 2017
Summary:
some server not work when upload a file with FromData in ios.
the reason is that there is a slash in boundary, like:
```
multipart/form-data; boundary=b/QeEbFgqK9PCZo4T/eXv7f.T74SHd5MxCZ846AsTz-yNV0xrRR_Zks4fkNMCzJck9ZE8o

// koa request.js (line 548)
  is(types) {
    if (!types) return typeis(this.req);
    if (!Array.isArray(types)) types = [].slice.call(arguments);
    return typeis(this.req, types);
  }

// type-is index.js (line 237)
function normalizeType (value) {
  // parse the type
  var type = typer.parse(value)

  // remove the parameters
  type.parameters = undefined

  // reformat it
  return typer.format(type)
}

// media-typer
var paramRegExp = /; *([!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) *= *("(?:[ !\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u0020-\u007e])*"|[!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) */g;
```

thanks for dougwilson 's [answer](jshttp/media-typer#5).
> The / is an illegal character for Content-Type, which is what this module parses
Closes facebook#11342

Differential Revision: D4326750

Pulled By: javache

fbshipit-source-id: b1c78a335c95a5c223537545d87beaffe15d673d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants