Skip to content

Commit

Permalink
fix: add Rack > 2.2.2 support
Browse files Browse the repository at this point in the history
The post was issuing a multi-part post with body. That is a malformed request and starting with Rack 2.2.2 will generate an exception. rack/rack#1603
This fixes that issue.
  • Loading branch information
rx committed Jun 16, 2021
1 parent 6968282 commit 6e23287
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
14 changes: 10 additions & 4 deletions public/bundle.js
Expand Up @@ -48739,9 +48739,7 @@ var VPosts = function (_VBase) {
}
}

var paramCount = Array.from(formData).length;

if (paramCount < 1) {
if (this.paramCount(formData) < 1) {
console.warn('Creating request with no data!' + ' Are you sure you\'ve hooked everything up correctly?');
}

Expand Down Expand Up @@ -48910,9 +48908,17 @@ var VPosts = function (_VBase) {
}

// Send our FormData object; HTTP headers are set automatically
httpRequest.send(formData);
// Rack 2.2 will throw an exception https://github.com/rack/rack/issues/1603
// if we set the header as multi-part form data with no data in the body
// So we set the body to null in this case.
httpRequest.send(_this2.paramCount(formData) < 1 ? null : formData);
});
}
}, {
key: 'paramCount',
value: function paramCount(formData) {
return Array.from(formData).length;
}
}, {
key: 'isForm',
value: function isForm() {
Expand Down
14 changes: 10 additions & 4 deletions public/wc.js
Expand Up @@ -34213,9 +34213,7 @@ var VPosts = function (_VBase) {
}
}

var paramCount = Array.from(formData).length;

if (paramCount < 1) {
if (this.paramCount(formData) < 1) {
console.warn('Creating request with no data!' + ' Are you sure you\'ve hooked everything up correctly?');
}

Expand Down Expand Up @@ -34384,9 +34382,17 @@ var VPosts = function (_VBase) {
}

// Send our FormData object; HTTP headers are set automatically
httpRequest.send(formData);
// Rack 2.2 will throw an exception https://github.com/rack/rack/issues/1603
// if we set the header as multi-part form data with no data in the body
// So we set the body to null in this case.
httpRequest.send(_this2.paramCount(formData) < 1 ? null : formData);
});
}
}, {
key: 'paramCount',
value: function paramCount(formData) {
return Array.from(formData).length;
}
}, {
key: 'isForm',
value: function isForm() {
Expand Down
16 changes: 10 additions & 6 deletions views/mdc/assets/js/components/events/posts.js
Expand Up @@ -59,13 +59,10 @@ export class VPosts extends VBase {
formData.append(name, encode(value));
}

const paramCount = Array.from(formData).length;

if (paramCount < 1) {
if (this.paramCount(formData) < 1) {
console.warn(
'Creating request with no data!'
+ ' Are you sure you\'ve hooked everything up correctly?',
);
+ ' Are you sure you\'ve hooked everything up correctly?');
}

let errors = this.validate(formData);
Expand Down Expand Up @@ -185,10 +182,17 @@ export class VPosts extends VBase {
}

// Send our FormData object; HTTP headers are set automatically
httpRequest.send(formData);
// Rack 2.2 will throw an exception https://github.com/rack/rack/issues/1603
// if we set the header as multi-part form data with no data in the body
// So we set the body to null in this case.
httpRequest.send(this.paramCount(formData) < 1 ? null : formData);
});
}

paramCount(formData){
return Array.from(formData).length;
}

isForm() {
var parentElement = this.parentElement();
return parentElement && parentElement.elements;
Expand Down

0 comments on commit 6e23287

Please sign in to comment.