aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2020-01-24 09:48:55 -0500
committerGitHub <noreply@github.com>2020-01-24 09:48:55 -0500
commit0bd995cdf5a67b5121f143848e68e1b60ea589bf (patch)
tree6398f7b44b60a034a0a6bef57d81424293e1d6d3
parentbe409233fdf8d3578e0529ec150a3697788ba4c8 (diff)
parent4dd27e16487bada0e00e27f2f0c73bd0c8e59daa (diff)
downloadservo-0bd995cdf5a67b5121f143848e68e1b60ea589bf.tar.gz
servo-0bd995cdf5a67b5121f143848e68e1b60ea589bf.zip
Auto merge of #25561 - pshaughn:formdata-same-file, r=jdm
Make File objects roundtrip through FormData FormData.append now only creates a new File object if it needs to file-wrap a blob or set a filename, and not when appending an existing File with no filename override. The hardest part here was reading the specification in a way that matched browser behavior. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #24939 - [X] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
-rw-r--r--components/script/dom/formdata.rs13
-rw-r--r--tests/wpt/metadata/xhr/formdata-foreach.html.ini11
2 files changed, 10 insertions, 14 deletions
diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs
index fd69adbe337..10d1a11f18e 100644
--- a/components/script/dom/formdata.rs
+++ b/components/script/dom/formdata.rs
@@ -185,12 +185,19 @@ impl FormDataMethods for FormData {
impl FormData {
// https://xhr.spec.whatwg.org/#create-an-entry
- // Steps 3-4.
fn create_an_entry(&self, blob: &Blob, opt_filename: Option<USVString>) -> DomRoot<File> {
+ // Steps 3-4
let name = match opt_filename {
Some(filename) => DOMString::from(filename.0),
- None if blob.downcast::<File>().is_none() => DOMString::from("blob"),
- None => DOMString::from(""),
+ None => match blob.downcast::<File>() {
+ None => DOMString::from("blob"),
+ // If it is already a file and no filename was given,
+ // then neither step 3 nor step 4 happens, so instead of
+ // creating a new File object we use the existing one.
+ Some(file) => {
+ return DomRoot::from_ref(file);
+ },
+ },
};
let bytes = blob.get_bytes().unwrap_or(vec![]);
diff --git a/tests/wpt/metadata/xhr/formdata-foreach.html.ini b/tests/wpt/metadata/xhr/formdata-foreach.html.ini
deleted file mode 100644
index 9d83f5a5b64..00000000000
--- a/tests/wpt/metadata/xhr/formdata-foreach.html.ini
+++ /dev/null
@@ -1,11 +0,0 @@
-[formdata-foreach.html]
- type: testharness
- [Iterator should return duplicate keys and non-deleted values]
- expected: FAIL
-
- [Entries iterator should return duplicate keys and non-deleted values]
- expected: FAIL
-
- [Values iterator should return non-deleted values]
- expected: FAIL
-