formdata-polyfill
Advanced tools
Comparing version 3.0.13 to 3.0.14
@@ -106,2 +106,11 @@ if (typeof FormData === 'undefined' || !FormData.prototype.keys) { | ||
// normalize linefeeds for textareas | ||
// https://html.spec.whatwg.org/multipage/form-elements.html#textarea-line-break-normalisation-transformation | ||
function normalizeLinefeeds(value) { | ||
if (typeof value === "string") { | ||
value = value.replace(/\r\n/g, "\n").replace(/\n/g, "\r\n") | ||
} | ||
return value | ||
} | ||
function each (arr, cb) { | ||
@@ -145,3 +154,4 @@ for (let i = 0; i < arr.length; i++) { | ||
} else { | ||
self.append(elm.name, elm.value) | ||
const value = elm.type === 'textarea' ? normalizeLinefeeds(elm.value) : elm.value | ||
self.append(elm.name, value) | ||
} | ||
@@ -148,0 +158,0 @@ }) |
@@ -8,11 +8,11 @@ ;(function(){var k;function l(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}}var m="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,d){a!=Array.prototype&&a!=Object.prototype&&(a[b]=d.value)},n="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;function p(){p=function(){};n.Symbol||(n.Symbol=r)}var r=function(){var a=0;return function(b){return"jscomp_symbol_"+(b||"")+a++}}(); | ||
function L(a){this.next=function(b){return a.h(b)};this["throw"]=function(b){return a.i(b)};this["return"]=function(b){return K(a,b)};u();this[Symbol.iterator]=function(){return this}}function M(a,b){var d=new L(new H(b));C&&C(d,a.prototype);return d} | ||
if("undefined"===typeof FormData||!FormData.prototype.keys){var N=function(a,b){for(var d=0;d<a.length;d++)b(a[d])},O=function(a,b,d){if(2>arguments.length)throw new TypeError("2 arguments required, but only "+arguments.length+" present.");return b instanceof Blob?[a+"",b,void 0!==d?d+"":"string"===typeof b.name?b.name:"blob"]:[a+"",b+""]},P=function(a){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");return[a+""]},Q=function(a){var b=x(a);a=b.next().value;b=b.next().value; | ||
a instanceof Blob&&(a=new File([a],b,{type:a.type,lastModified:a.lastModified}));return a},R="object"===typeof window?window:"object"===typeof self?self:this,S=R.FormData,T=R.XMLHttpRequest&&R.XMLHttpRequest.prototype.send,U=R.Request&&R.fetch;p();var V=R.Symbol&&Symbol.toStringTag,W=new WeakMap,X=Array.from||function(a){return[].slice.call(a)};V&&(Blob.prototype[V]||(Blob.prototype[V]="Blob"),"File"in R&&!File.prototype[V]&&(File.prototype[V]="File"));try{new File([],"")}catch(a){R.File=function(b, | ||
d,c){b=new Blob(b,c);c=c&&void 0!==c.lastModified?new Date(c.lastModified):new Date;Object.defineProperties(b,{name:{value:d},lastModifiedDate:{value:c},lastModified:{value:+c},toString:{value:function(){return"[object File]"}}});V&&Object.defineProperty(b,V,{value:"File"});return b}}p();u();var Y=function(a){W.set(this,Object.create(null));if(!a)return this;var b=this;N(a.elements,function(a){a.name&&!a.disabled&&"submit"!==a.type&&"button"!==a.type&&("file"===a.type?N(a.files||[],function(c){b.append(a.name, | ||
c)}):"select-multiple"===a.type||"select-one"===a.type?N(a.options,function(c){!c.disabled&&c.selected&&b.append(a.name,c.value)}):"checkbox"===a.type||"radio"===a.type?a.checked&&b.append(a.name,a.value):b.append(a.name,a.value))})};k=Y.prototype;k.append=function(a,b,d){var c=W.get(this);c[a]||(c[a]=[]);c[a].push([b,d])};k["delete"]=function(a){delete W.get(this)[a]};k.entries=function b(){var d=this,c,e,f,g,h,q;return M(b,function(b){switch(b.b){case 1:c=W.get(d),f=new G(c);case 2:var t;a:{for(t= | ||
f;0<t.j.length;){var w=t.j.pop();if(w in t.w){t=w;break a}}t=null}if(null==(e=t)){b.b=0;break}g=x(c[e]);h=g.next();case 5:if(h.done){b.b=2;break}q=h.value;return F(b,[e,Q(q)],6);case 6:h=g.next(),b.b=5}})};k.forEach=function(b,d){for(var c=x(this),e=c.next();!e.done;e=c.next()){var f=x(e.value);e=f.next().value;f=f.next().value;b.call(d,f,e,this)}};k.get=function(b){var d=W.get(this);return d[b]?Q(d[b][0]):null};k.getAll=function(b){return(W.get(this)[b]||[]).map(Q)};k.has=function(b){return b in | ||
W.get(this)};k.keys=function d(){var c=this,e,f,g,h,q;return M(d,function(d){1==d.b&&(e=x(c),f=e.next());if(3!=d.b){if(f.done){d.b=0;return}g=f.value;h=x(g);q=h.next().value;return F(d,q,3)}f=e.next();d.b=2})};k.set=function(d,c,e){W.get(this)[d]=[[c,e]]};k.values=function c(){var e=this,f,g,h,q,w;return M(c,function(c){1==c.b&&(f=x(e),g=f.next());if(3!=c.b){if(g.done){c.b=0;return}h=g.value;q=x(h);q.next();w=q.next().value;return F(c,w,3)}g=f.next();c.b=2})};Y.prototype._asNative=function(){for(var c= | ||
new S,e=x(this),f=e.next();!f.done;f=e.next()){var g=x(f.value);f=g.next().value;g=g.next().value;c.append(f,g)}return c};Y.prototype._blob=function(){for(var c="----formdata-polyfill-"+Math.random(),e=[],f=x(this),g=f.next();!g.done;g=f.next()){var h=x(g.value);g=h.next().value;h=h.next().value;e.push("--"+c+"\r\n");h instanceof Blob?e.push('Content-Disposition: form-data; name="'+g+'"; filename="'+h.name+'"\r\n',"Content-Type: "+(h.type||"application/octet-stream")+"\r\n\r\n",h,"\r\n"):e.push('Content-Disposition: form-data; name="'+ | ||
g+'"\r\n\r\n'+h+"\r\n")}e.push("--"+c+"--");return new Blob(e,{type:"multipart/form-data; boundary="+c})};Y.prototype[Symbol.iterator]=function(){return this.entries()};Y.prototype.toString=function(){return"[object FormData]"};V&&(Y.prototype[V]="FormData");[["append",O],["delete",P],["get",P],["getAll",P],["has",P],["set",O]].forEach(function(c){var e=Y.prototype[c[0]];Y.prototype[c[0]]=function(){return e.apply(this,c[1].apply(this,X(arguments)))}});T&&(XMLHttpRequest.prototype.send=function(c){c instanceof | ||
Y?(c=c._blob(),this.setRequestHeader("Content-Type",c.type),T.call(this,c)):T.call(this,c)});if(U){var Z=R.fetch;R.fetch=function(c,e){e&&e.body&&e.body instanceof Y&&(e.body=e.body._blob());return Z(c,e)}}R.FormData=Y}; | ||
if("undefined"===typeof FormData||!FormData.prototype.keys){var N=function(a,b){for(var d=0;d<a.length;d++)b(a[d])},O=function(a){"string"===typeof a&&(a=a.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"));return a},P=function(a,b,d){if(2>arguments.length)throw new TypeError("2 arguments required, but only "+arguments.length+" present.");return b instanceof Blob?[a+"",b,void 0!==d?d+"":"string"===typeof b.name?b.name:"blob"]:[a+"",b+""]},Q=function(a){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present."); | ||
return[a+""]},R=function(a){var b=x(a);a=b.next().value;b=b.next().value;a instanceof Blob&&(a=new File([a],b,{type:a.type,lastModified:a.lastModified}));return a},S="object"===typeof window?window:"object"===typeof self?self:this,T=S.FormData,U=S.XMLHttpRequest&&S.XMLHttpRequest.prototype.send,V=S.Request&&S.fetch;p();var W=S.Symbol&&Symbol.toStringTag,X=new WeakMap,Y=Array.from||function(a){return[].slice.call(a)};W&&(Blob.prototype[W]||(Blob.prototype[W]="Blob"),"File"in S&&!File.prototype[W]&& | ||
(File.prototype[W]="File"));try{new File([],"")}catch(a){S.File=function(b,d,c){b=new Blob(b,c);c=c&&void 0!==c.lastModified?new Date(c.lastModified):new Date;Object.defineProperties(b,{name:{value:d},lastModifiedDate:{value:c},lastModified:{value:+c},toString:{value:function(){return"[object File]"}}});W&&Object.defineProperty(b,W,{value:"File"});return b}}p();u();var Z=function(a){X.set(this,Object.create(null));if(!a)return this;var b=this;N(a.elements,function(a){if(a.name&&!a.disabled&&"submit"!== | ||
a.type&&"button"!==a.type)if("file"===a.type)N(a.files||[],function(c){b.append(a.name,c)});else if("select-multiple"===a.type||"select-one"===a.type)N(a.options,function(c){!c.disabled&&c.selected&&b.append(a.name,c.value)});else if("checkbox"===a.type||"radio"===a.type)a.checked&&b.append(a.name,a.value);else{var c="textarea"===a.type?O(a.value):a.value;b.append(a.name,c)}})};k=Z.prototype;k.append=function(a,b,d){var c=X.get(this);c[a]||(c[a]=[]);c[a].push([b,d])};k["delete"]=function(a){delete X.get(this)[a]}; | ||
k.entries=function b(){var d=this,c,e,f,g,h,q;return M(b,function(b){switch(b.b){case 1:c=X.get(d),f=new G(c);case 2:var t;a:{for(t=f;0<t.j.length;){var w=t.j.pop();if(w in t.w){t=w;break a}}t=null}if(null==(e=t)){b.b=0;break}g=x(c[e]);h=g.next();case 5:if(h.done){b.b=2;break}q=h.value;return F(b,[e,R(q)],6);case 6:h=g.next(),b.b=5}})};k.forEach=function(b,d){for(var c=x(this),e=c.next();!e.done;e=c.next()){var f=x(e.value);e=f.next().value;f=f.next().value;b.call(d,f,e,this)}};k.get=function(b){var d= | ||
X.get(this);return d[b]?R(d[b][0]):null};k.getAll=function(b){return(X.get(this)[b]||[]).map(R)};k.has=function(b){return b in X.get(this)};k.keys=function d(){var c=this,e,f,g,h,q;return M(d,function(d){1==d.b&&(e=x(c),f=e.next());if(3!=d.b){if(f.done){d.b=0;return}g=f.value;h=x(g);q=h.next().value;return F(d,q,3)}f=e.next();d.b=2})};k.set=function(d,c,e){X.get(this)[d]=[[c,e]]};k.values=function c(){var e=this,f,g,h,q,w;return M(c,function(c){1==c.b&&(f=x(e),g=f.next());if(3!=c.b){if(g.done){c.b= | ||
0;return}h=g.value;q=x(h);q.next();w=q.next().value;return F(c,w,3)}g=f.next();c.b=2})};Z.prototype._asNative=function(){for(var c=new T,e=x(this),f=e.next();!f.done;f=e.next()){var g=x(f.value);f=g.next().value;g=g.next().value;c.append(f,g)}return c};Z.prototype._blob=function(){for(var c="----formdata-polyfill-"+Math.random(),e=[],f=x(this),g=f.next();!g.done;g=f.next()){var h=x(g.value);g=h.next().value;h=h.next().value;e.push("--"+c+"\r\n");h instanceof Blob?e.push('Content-Disposition: form-data; name="'+ | ||
g+'"; filename="'+h.name+'"\r\n',"Content-Type: "+(h.type||"application/octet-stream")+"\r\n\r\n",h,"\r\n"):e.push('Content-Disposition: form-data; name="'+g+'"\r\n\r\n'+h+"\r\n")}e.push("--"+c+"--");return new Blob(e,{type:"multipart/form-data; boundary="+c})};Z.prototype[Symbol.iterator]=function(){return this.entries()};Z.prototype.toString=function(){return"[object FormData]"};W&&(Z.prototype[W]="FormData");[["append",P],["delete",Q],["get",Q],["getAll",Q],["has",Q],["set",P]].forEach(function(c){var e= | ||
Z.prototype[c[0]];Z.prototype[c[0]]=function(){return e.apply(this,c[1].apply(this,Y(arguments)))}});U&&(XMLHttpRequest.prototype.send=function(c){c instanceof Z?(c=c._blob(),this.setRequestHeader("Content-Type",c.type),U.call(this,c)):U.call(this,c)});if(V){var aa=S.fetch;S.fetch=function(c,e){e&&e.body&&e.body instanceof Z&&(e.body=e.body._blob());return aa(c,e)}}S.FormData=Z}; | ||
})(); |
{ | ||
"name": "formdata-polyfill", | ||
"version": "3.0.13", | ||
"version": "3.0.14", | ||
"description": "HTML5 `FormData` polyfill for Browsers.", | ||
@@ -29,3 +29,3 @@ "main": "formdata.min.js", | ||
"chai": "^4.2.0", | ||
"karma": "^3.1.1", | ||
"karma": "^4.0.0", | ||
"karma-chai": "^0.1.0", | ||
@@ -32,0 +32,0 @@ "karma-chrome-launcher": "^2.2.0", |
@@ -63,5 +63,7 @@ # FormData | ||
The status of the native FormData (2016-10-19) is: | ||
[![skarmavbild 2016-10-19 kl 21 32 19](https://cloud.githubusercontent.com/assets/1148376/19534352/b7f42d8c-9643-11e6-91da-7f89580f51d8.png)](https://developer.mozilla.org/en-US/docs/Web/API/FormData#Browser_compatibility) | ||
The status of the native FormData (2018-11-15) is: | ||
[![skarmavbild 2018-11-15 kl 20 16 36](https://user-images.githubusercontent.com/1148376/48575973-99df5180-e913-11e8-8456-24f274d70fab.png)](https://developer.mozilla.org/en-US/docs/Web/API/FormData#Browser_compatibility) | ||
This polyfill normalizes support for the FormData API: | ||
@@ -68,0 +70,0 @@ |
@@ -172,2 +172,52 @@ const native = window.FormData | ||
describe('linebreaks', () => { | ||
// Native FormData normalizes linefeeds in textareas to CRLF | ||
// In order to be consistent the polyfill should do the same | ||
it('Should convert LF to CRLF for textareas', () => { | ||
// This can not be tested with 'create_form' as the function ignores \n | ||
const form = document.createElement('form') | ||
const textarea = document.createElement('textarea') | ||
textarea.name = 'key' | ||
textarea.value = '\n' | ||
form.appendChild(textarea) | ||
const fd = new FormData(form) | ||
const value = fd.get('key') | ||
assert.equal('\r\n', value) | ||
}) | ||
it('Should convert CR to CRLF for textareas', () => { | ||
const form = document.createElement('form') | ||
const textarea = document.createElement('textarea') | ||
textarea.name = 'key' | ||
textarea.value = '\r' | ||
form.appendChild(textarea) | ||
const fd = new FormData(form) | ||
const value = fd.get('key') | ||
assert.equal('\r\n', value) | ||
}) | ||
it('Should normalize mixed linefeeds to CRLF for textareas', () => { | ||
const form = document.createElement('form') | ||
const textarea = document.createElement('textarea') | ||
textarea.name = 'key' | ||
textarea.value = 'a\n\ra\r\na\n\r\n\r\n\r\n\na\r\r' | ||
form.appendChild(textarea) | ||
const fd = new FormData(form) | ||
const value = fd.get('key') | ||
assert.equal('a\r\n\r\na\r\na\r\n\r\n\r\n\r\n\r\na\r\n\r\n', value) | ||
}) | ||
it('Should not convert LF to CRLF when provided by append', () => { | ||
const fd = create_formdata(['key', '\n']) | ||
const value = fd.get('key') | ||
assert.equal('\n', value) | ||
}) | ||
it('Should not convert CR to CRLF when provided by append', () => { | ||
const fd = create_formdata(['key', '\r']) | ||
const value = fd.get('key') | ||
assert.equal('\r', value) | ||
}) | ||
}) | ||
describe('disabled', () => { | ||
@@ -174,0 +224,0 @@ it('Shold not include disabled fields', () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33284
10
655
78