mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
🐛 Fixed redirects.json file corruption on upload
refs 91efa4605c
- Referenced commit introduced a double json-stringification to uploaded redirects.json files.
- The endpoint has no stability index of any sort and is meant to be dropped in Ghost v5. It's best to rework the redirects to the yaml format as descirbe here - https://ghost.org/docs/tutorials/implementing-redirects/#file-structure
This commit is contained in:
parent
621cfd9866
commit
3315ed34ae
2 changed files with 22 additions and 1 deletions
|
@ -237,7 +237,7 @@ class CustomRedirectsAPI {
|
|||
validation.validate(parsed);
|
||||
|
||||
if (ext === '.json') {
|
||||
await fs.writeFile(this.createRedirectsFilePath('.json'), JSON.stringify(content), 'utf-8');
|
||||
await fs.writeFile(this.createRedirectsFilePath('.json'), JSON.stringify(parsed), 'utf-8');
|
||||
} else if (ext === '.yaml') {
|
||||
await fs.copy(filePath, this.createRedirectsFilePath('.yaml'));
|
||||
}
|
||||
|
|
|
@ -68,6 +68,12 @@ describe('Redirects API', function () {
|
|||
|
||||
const dataFiles = fs.readdirSync(config.getContentPath('data'));
|
||||
dataFiles.join(',').match(/(redirects)/g).length.should.eql(2);
|
||||
|
||||
const fileContent = fs.readFileSync(path.join(contentFolder, 'data', 'redirects.json'), 'utf-8');
|
||||
fileContent.should.eql(JSON.stringify([{
|
||||
from: 'k',
|
||||
to: 'l'
|
||||
}]));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -143,6 +149,12 @@ describe('Redirects API', function () {
|
|||
.then(() => {
|
||||
const dataFiles = fs.readdirSync(config.getContentPath('data'));
|
||||
dataFiles.join(',').match(/(redirects)/g).length.should.eql(3);
|
||||
|
||||
const fileContent = fs.readFileSync(path.join(config.get('paths:contentPath'), 'data', 'redirects.json'), 'utf-8');
|
||||
fileContent.should.eql(JSON.stringify([{
|
||||
from: 'e',
|
||||
to: 'b'
|
||||
}]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -198,6 +210,9 @@ describe('Redirects API', function () {
|
|||
const dataFiles = fs.readdirSync(config.getContentPath('data'));
|
||||
dataFiles.join(',').match(/(redirects)/g).length.should.eql(2);
|
||||
|
||||
const fileContent = fs.readFileSync(path.join(config.get('paths:contentPath'), 'data', 'redirects.yaml'), 'utf-8');
|
||||
fileContent.should.eql('302:\n c: d');
|
||||
|
||||
// Provide another redirects file in the root directory of the content test folder
|
||||
fs.writeFileSync(path.join(config.get('paths:contentPath'), 'redirects-something.json'), JSON.stringify([{
|
||||
from: 'e',
|
||||
|
@ -229,6 +244,12 @@ describe('Redirects API', function () {
|
|||
|
||||
const dataFiles = fs.readdirSync(config.getContentPath('data'));
|
||||
dataFiles.join(',').match(/(redirects)/g).length.should.eql(3);
|
||||
|
||||
const fileContent = fs.readFileSync(path.join(config.get('paths:contentPath'), 'data', 'redirects.json'), 'utf-8');
|
||||
fileContent.should.eql(JSON.stringify([{
|
||||
from: 'e',
|
||||
to: 'b'
|
||||
}]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue