Merge pull request #57 from boazpoolman/fix/invalid-filename-character
feat: Escape '/' with '$' in filenamespull/60/head
commit
829a50492c
|
@ -28,7 +28,7 @@
|
||||||
"uuid": "2e84e366-1e09-43c2-a99f-a0d0acbc2ca5"
|
"uuid": "2e84e366-1e09-43c2-a99f-a0d0acbc2ca5"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12.x.x <=16.x.x",
|
"node": ">=14.x.x <=16.x.x",
|
||||||
"npm": ">=6.0.0"
|
"npm": ">=6.0.0"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
|
|
|
@ -24,8 +24,9 @@ module.exports = () => ({
|
||||||
const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => `${configType}.${configName}`.startsWith(option)));
|
const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => `${configType}.${configName}`.startsWith(option)));
|
||||||
if (shouldExclude) return;
|
if (shouldExclude) return;
|
||||||
|
|
||||||
// Replace ':' with '#' in filenames for Windows support.
|
// Replace reserved characters in filenames.
|
||||||
configName = configName.replace(/:/g, "#");
|
configName = configName.replace(/:/g, "#");
|
||||||
|
configName = configName.replace(/\//g, "$");
|
||||||
|
|
||||||
// Check if the JSON content should be minified.
|
// Check if the JSON content should be minified.
|
||||||
const json = !strapi.config.get('plugin.config-sync').minify
|
const json = !strapi.config.get('plugin.config-sync').minify
|
||||||
|
@ -59,8 +60,9 @@ module.exports = () => ({
|
||||||
const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => configName.startsWith(option)));
|
const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => configName.startsWith(option)));
|
||||||
if (shouldExclude) return;
|
if (shouldExclude) return;
|
||||||
|
|
||||||
// Replace ':' with '#' in filenames for Windows support.
|
// Replace reserved characters in filenames.
|
||||||
configName = configName.replace(/:/g, "#");
|
configName = configName.replace(/:/g, "#");
|
||||||
|
configName = configName.replace(/\//g, "$");
|
||||||
|
|
||||||
fs.unlinkSync(`${strapi.config.get('plugin.config-sync.syncDir')}${configName}.json`);
|
fs.unlinkSync(`${strapi.config.get('plugin.config-sync.syncDir')}${configName}.json`);
|
||||||
},
|
},
|
||||||
|
@ -73,8 +75,9 @@ module.exports = () => ({
|
||||||
* @returns {object} The JSON content of the config file.
|
* @returns {object} The JSON content of the config file.
|
||||||
*/
|
*/
|
||||||
readConfigFile: async (configType, configName) => {
|
readConfigFile: async (configType, configName) => {
|
||||||
// Replace ':' with '#' in filenames for Windows support.
|
// Replace reserved characters in filenames.
|
||||||
configName = configName.replace(/:/g, "#");
|
configName = configName.replace(/:/g, "#");
|
||||||
|
configName = configName.replace(/\//g, "$");
|
||||||
|
|
||||||
const readFile = util.promisify(fs.readFile);
|
const readFile = util.promisify(fs.readFile);
|
||||||
return readFile(`${strapi.config.get('plugin.config-sync.syncDir')}${configType}.${configName}.json`)
|
return readFile(`${strapi.config.get('plugin.config-sync.syncDir')}${configType}.${configName}.json`)
|
||||||
|
@ -107,8 +110,9 @@ module.exports = () => ({
|
||||||
const type = file.split('.')[0]; // Grab the first part of the filename.
|
const type = file.split('.')[0]; // Grab the first part of the filename.
|
||||||
const name = file.split(/\.(.+)/)[1].split('.').slice(0, -1).join('.'); // Grab the rest of the filename minus the file extension.
|
const name = file.split(/\.(.+)/)[1].split('.').slice(0, -1).join('.'); // Grab the rest of the filename minus the file extension.
|
||||||
|
|
||||||
// Replace ':' with '#' in filenames for Windows support.
|
// Put back reserved characters from filenames.
|
||||||
const formattedName = name.replace(/#/g, ":");
|
let formattedName = name.replace(/#/g, ":");
|
||||||
|
formattedName = name.replace(/\$/g, "/");
|
||||||
|
|
||||||
if (
|
if (
|
||||||
configType && configType !== type
|
configType && configType !== type
|
||||||
|
|
Loading…
Reference in New Issue