Skip to content

Commit a6035e1

Browse files
committed
fix: Character escaping
1 parent 829a504 commit a6035e1

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

server/services/main.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ module.exports = () => ({
2525
if (shouldExclude) return;
2626

2727
// Replace reserved characters in filenames.
28-
configName = configName.replace(/:/g, "#");
29-
configName = configName.replace(/\//g, "$");
28+
configName = configName.replace(/:/g, "#").replace(/\//g, "$");
3029

3130
// Check if the JSON content should be minified.
3231
const json = !strapi.config.get('plugin.config-sync').minify
@@ -61,8 +60,7 @@ module.exports = () => ({
6160
if (shouldExclude) return;
6261

6362
// Replace reserved characters in filenames.
64-
configName = configName.replace(/:/g, "#");
65-
configName = configName.replace(/\//g, "$");
63+
configName = configName.replace(/:/g, "#").replace(/\//g, "$");
6664

6765
fs.unlinkSync(`${strapi.config.get('plugin.config-sync.syncDir')}${configName}.json`);
6866
},
@@ -76,8 +74,7 @@ module.exports = () => ({
7674
*/
7775
readConfigFile: async (configType, configName) => {
7876
// Replace reserved characters in filenames.
79-
configName = configName.replace(/:/g, "#");
80-
configName = configName.replace(/\//g, "$");
77+
configName = configName.replace(/:/g, "#").replace(/\//g, "$");
8178

8279
const readFile = util.promisify(fs.readFile);
8380
return readFile(`${strapi.config.get('plugin.config-sync.syncDir')}${configType}.${configName}.json`)
@@ -111,8 +108,7 @@ module.exports = () => ({
111108
const name = file.split(/\.(.+)/)[1].split('.').slice(0, -1).join('.'); // Grab the rest of the filename minus the file extension.
112109

113110
// Put back reserved characters from filenames.
114-
let formattedName = name.replace(/#/g, ":");
115-
formattedName = name.replace(/\$/g, "/");
111+
const formattedName = name.replace(/#/g, ":").replace(/\$/g, "/");
116112

117113
if (
118114
configType && configType !== type

0 commit comments

Comments
 (0)