Skip to content

Commit fd687e0

Browse files
committed
fix: @putout/operator-filesystem: readFileContent: avoid content decoding when has spaces
1 parent 0142889 commit fd687e0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/operator-filesystem/lib/filesystem.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ const toBase64 = (content) => {
4343
};
4444

4545
const fromBase64 = (content) => {
46+
if (content.includes(' '))
47+
return content;
48+
4649
const [e, decoded] = tryCatch(atob, content);
4750

4851
if (!e)

packages/operator-filesystem/lib/filesystem.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,20 @@ test('putout: operator: filesystem: readFileContent: no content: should create:
10471047
t.end();
10481048
});
10491049

1050+
test('putout: operator: filesystem: readFileContent: literal', (t) => {
1051+
const content = `export default 5\n`;
1052+
const ast = parseFilesystem([
1053+
'/',
1054+
['/a.js', content],
1055+
]);
1056+
1057+
const [filePath] = findFile(ast, 'a.js');
1058+
const result = readFileContent(filePath);
1059+
1060+
t.equal(result, content);
1061+
t.end();
1062+
});
1063+
10501064
test('putout: operator: filesystem: createFile', (t) => {
10511065
const ast = parseFilesystem({
10521066
type: 'directory',

0 commit comments

Comments
 (0)