From c39c18d48c557f9f206396eb73e20f15b0a85e7e Mon Sep 17 00:00:00 2001 From: Russell Edens Date: Wed, 16 Jun 2021 17:09:31 -0400 Subject: [PATCH] fix: add Rack > 2.2.2 support 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. https://github.com/rack/rack/issues/1603 This fixes that issue. --- public/bundle.js | 14 ++++++++++---- public/wc.js | 14 ++++++++++---- views/mdc/assets/js/components/events/posts.js | 16 ++++++++++------ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/public/bundle.js b/public/bundle.js index 32ae819b..783429de 100644 --- a/public/bundle.js +++ b/public/bundle.js @@ -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?'); } @@ -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() { diff --git a/public/wc.js b/public/wc.js index a86261e6..4fe0e0fd 100644 --- a/public/wc.js +++ b/public/wc.js @@ -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?'); } @@ -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() { diff --git a/views/mdc/assets/js/components/events/posts.js b/views/mdc/assets/js/components/events/posts.js index a6a3d00d..c7f82a54 100644 --- a/views/mdc/assets/js/components/events/posts.js +++ b/views/mdc/assets/js/components/events/posts.js @@ -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); @@ -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;