mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Merge pull request #2566 from jaswilli/fix/issue-2563
Build correct path on image upload when config has custom content path
This commit is contained in:
commit
0bf2a5ada0
2 changed files with 32 additions and 2 deletions
|
@ -33,7 +33,7 @@ localFileStore = _.extend(baseStore, {
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
// The src for the image must be in URI format, not a file system path, which in Windows uses \
|
// The src for the image must be in URI format, not a file system path, which in Windows uses \
|
||||||
// For local file system storage can use relative path so add a slash
|
// For local file system storage can use relative path so add a slash
|
||||||
var fullUrl = (config().paths.subdir + '/' + path.relative(config().paths.appRoot, targetFilename)).replace(new RegExp('\\' + path.sep, 'g'), '/');
|
var fullUrl = (config().paths.subdir + '/' + config().paths.imagesRelPath + '/' + path.relative(config().paths.imagesPath, targetFilename)).replace(new RegExp('\\' + path.sep, 'g'), '/');
|
||||||
return saved.resolve(fullUrl);
|
return saved.resolve(fullUrl);
|
||||||
}).otherwise(function (e) {
|
}).otherwise(function (e) {
|
||||||
errors.logError(e);
|
errors.logError(e);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
var fs = require('fs-extra'),
|
var fs = require('fs-extra'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
should = require('should'),
|
should = require('should'),
|
||||||
|
config = require('../../server/config'),
|
||||||
sinon = require('sinon'),
|
sinon = require('sinon'),
|
||||||
when = require('when'),
|
when = require('when'),
|
||||||
localfilesystem = require('../../server/storage/localfilesystem');
|
localfilesystem = require('../../server/storage/localfilesystem');
|
||||||
|
@ -122,6 +123,27 @@ describe('Local File System Storage', function () {
|
||||||
}).then(null, done);
|
}).then(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when a custom content path is used', function () {
|
||||||
|
var origContentPath = config().paths.contentPath;
|
||||||
|
var origImagesPath = config().paths.imagesPath;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
config().paths.contentPath = config().paths.appRoot + '/var/ghostcms';
|
||||||
|
config().paths.imagesPath = config().paths.appRoot + '/var/ghostcms/' + config().paths.imagesRelPath;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
config().paths.contentPath = origContentPath;
|
||||||
|
config().paths.imagesPath = origImagesPath;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should send the correct path to image', function (done) {
|
||||||
|
localfilesystem.save(image).then(function (url) {
|
||||||
|
url.should.equal('/content/images/2013/Sep/IMAGE.jpg');
|
||||||
|
return done();
|
||||||
|
}).then(null, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('on Windows', function () {
|
describe('on Windows', function () {
|
||||||
var truePathSep = path.sep;
|
var truePathSep = path.sep;
|
||||||
|
@ -139,7 +161,15 @@ describe('Local File System Storage', function () {
|
||||||
path.sep = '\\';
|
path.sep = '\\';
|
||||||
path.join.returns('content\\images\\2013\\Sep\\IMAGE.jpg');
|
path.join.returns('content\\images\\2013\\Sep\\IMAGE.jpg');
|
||||||
localfilesystem.save(image).then(function (url) {
|
localfilesystem.save(image).then(function (url) {
|
||||||
url.should.equal('/content/images/2013/Sep/IMAGE.jpg');
|
if (truePathSep === '\\') {
|
||||||
|
url.should.equal('/content/images/2013/Sep/IMAGE.jpg');
|
||||||
|
} else {
|
||||||
|
// if this unit test is run on an OS that uses forward slash separators,
|
||||||
|
// localfilesystem.save() will use a path.relative() call on
|
||||||
|
// one path with backslash separators and one path with forward
|
||||||
|
// slashes and it returns a path that needs to be normalized
|
||||||
|
path.normalize(url).should.equal('/content/images/2013/Sep/IMAGE.jpg');
|
||||||
|
}
|
||||||
return done();
|
return done();
|
||||||
}).then(null, done);
|
}).then(null, done);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue