🐛 Supported "false" as absolute attribute value (#10556)

no-issue

* Added breaking test
* 🐛 Supported "false" as absolute attribute value

refs https://github.com/TryGhost/docs-api/pull/29
This commit is contained in:
Fabien O'Carroll 2019-03-04 11:23:42 +01:00 committed by GitHub
parent 42c472feff
commit d7238e94c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 4 deletions

View File

@ -19,7 +19,7 @@ module.exports = function imgUrl(attr, options) {
return;
}
const absolute = options && options.hash && options.hash.absolute;
const absolute = options && options.hash && options.hash.absolute && options.hash.absolute !== 'false';
const size = options && options.hash && options.hash.size;
const imageSizes = options && options.data && options.data.config && options.data.config.image_sizes;

View File

@ -9,7 +9,7 @@ var proxy = require('./proxy'),
getMetaDataUrl = proxy.metaData.getMetaDataUrl;
module.exports = function url(options) {
var absolute = options && options.hash.absolute,
var absolute = options && options.hash.absolute && options.hash.absolute !== 'false',
outputUrl = getMetaDataUrl(this, absolute);
outputUrl = encodeURI(decodeURI(outputUrl));

View File

@ -39,6 +39,12 @@ describe('{{image}} helper', function () {
logWarnStub.called.should.be.false();
});
it('should NOT output absolute url of image if the option is "false" ', function () {
var rendered = helpers.img_url('/content/images/image-relative-url.png', {hash: {absolute: 'false'}});
should.exist(rendered);
rendered.should.equal('/content/images/image-relative-url.png');
});
it('should output author url', function () {
var rendered = helpers.img_url('/content/images/author-image-relative-url.png', {});
should.exist(rendered);

View File

@ -60,7 +60,7 @@ describe('{{url}} helper', function () {
created_at: new Date(0)
});
urlService.getUrlByResourceId.withArgs(post.id, {absolute: 'true', secure: undefined, withSubdirectory: true}).returns('http://localhost:82832/slug/');
urlService.getUrlByResourceId.withArgs(post.id, {absolute: true, secure: undefined, withSubdirectory: true}).returns('http://localhost:82832/slug/');
rendered = helpers.url.call(post, {hash: {absolute: 'true'}});
should.exist(rendered);
@ -78,7 +78,7 @@ describe('{{url}} helper', function () {
secure: true
});
urlService.getUrlByResourceId.withArgs(post.id, {absolute: 'true', secure: true, withSubdirectory: true}).returns('https://localhost:82832/slug/');
urlService.getUrlByResourceId.withArgs(post.id, {absolute: true, secure: true, withSubdirectory: true}).returns('https://localhost:82832/slug/');
rendered = helpers.url.call(post, {hash: {absolute: 'true'}});
should.exist(rendered);