MDL-76039 forms: account for null values in serialize util method.

Co-authored-by: Marina Glancy <marina@moodle.com>
This commit is contained in:
Paul Holden 2022-10-19 16:52:11 +01:00
parent 7c3188b2ca
commit 7012900d08
3 changed files with 3 additions and 3 deletions

View File

@ -1,3 +1,3 @@
define("core_form/util",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.serialize=void 0;const serialize=function(data){let prefix=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return[...Object.entries(data).map((_ref=>{let[index,value]=_ref;const key=prefix?"".concat(prefix,"[").concat(index,"]"):index;return"object"==typeof value?serialize(value,key):"".concat(key,"=").concat(encodeURIComponent(value))}))].join("&")};_exports.serialize=serialize}));
define("core_form/util",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.serialize=void 0;const serialize=function(data){let prefix=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return[...Object.entries(data).map((_ref=>{let[index,value]=_ref;const key=prefix?"".concat(prefix,"[").concat(index,"]"):index;return null!==value&&"object"==typeof value?serialize(value,key):"".concat(key,"=").concat(encodeURIComponent(value))}))].join("&")};_exports.serialize=serialize}));
//# sourceMappingURL=util.min.js.map

View File

@ -1 +1 @@
{"version":3,"file":"util.min.js","sources":["../src/util.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Serialize form values into a string.\n *\n * This must be used instead of URLSearchParams, which does not correctly encode nested values such as arrays.\n *\n * @param {Object} data The form values to serialize\n * @param {string} prefix The prefix to use for key names\n * @returns {string}\n */\nexport const serialize = (data, prefix = '') => [\n ...Object.entries(data).map(([index, value]) => {\n const key = prefix ? `${prefix}[${index}]` : index;\n return (typeof value === \"object\") ? serialize(value, key) : `${key}=${encodeURIComponent(value)}`;\n })\n].join(\"&\");\n"],"names":["serialize","data","prefix","Object","entries","map","_ref","index","value","key","encodeURIComponent","join"],"mappings":"gJAwBaA,UAAY,SAACC,UAAMC,8DAAS,SAAO,IACzCC,OAAOC,QAAQH,MAAMI,KAAIC,WAAEC,MAAOC,kBAC3BC,IAAMP,iBAAYA,mBAAUK,WAAWA,YACpB,iBAAVC,MAAsBR,UAAUQ,MAAOC,eAAUA,gBAAOC,mBAAmBF,YAEhGG,KAAK"}
{"version":3,"file":"util.min.js","sources":["../src/util.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Serialize form values into a string.\n *\n * This must be used instead of URLSearchParams, which does not correctly encode nested values such as arrays.\n *\n * @param {Object} data The form values to serialize\n * @param {string} prefix The prefix to use for key names\n * @returns {string}\n */\nexport const serialize = (data, prefix = '') => [\n ...Object.entries(data).map(([index, value]) => {\n const key = prefix ? `${prefix}[${index}]` : index;\n return (value !== null && typeof value === \"object\") ? serialize(value, key) : `${key}=${encodeURIComponent(value)}`;\n })\n].join(\"&\");\n"],"names":["serialize","data","prefix","Object","entries","map","_ref","index","value","key","encodeURIComponent","join"],"mappings":"gJAwBaA,UAAY,SAACC,UAAMC,8DAAS,SAAO,IACzCC,OAAOC,QAAQH,MAAMI,KAAIC,WAAEC,MAAOC,kBAC3BC,IAAMP,iBAAYA,mBAAUK,WAAWA,aAC3B,OAAVC,OAAmC,iBAAVA,MAAsBR,UAAUQ,MAAOC,eAAUA,gBAAOC,mBAAmBF,YAElHG,KAAK"}

View File

@ -25,6 +25,6 @@
export const serialize = (data, prefix = '') => [
...Object.entries(data).map(([index, value]) => {
const key = prefix ? `${prefix}[${index}]` : index;
return (typeof value === "object") ? serialize(value, key) : `${key}=${encodeURIComponent(value)}`;
return (value !== null && typeof value === "object") ? serialize(value, key) : `${key}=${encodeURIComponent(value)}`;
})
].join("&");