Skip to content

Commit

Permalink
[fix] don't urlescape path of post asset
Browse files Browse the repository at this point in the history
fixes hexojs#1562

Changes to be committed:
	modified:   lib/models/post_asset.js
	modified:   test/scripts/tags/asset_img.js
  • Loading branch information
leesei committed Feb 23, 2016
1 parent 9aca27b commit 4354260
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/models/post_asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var Schema = require('warehouse').Schema;
var pathFn = require('path');
var url = require('url');

module.exports = function(ctx) {
var PostAsset = new Schema({
Expand All @@ -18,7 +17,9 @@ module.exports = function(ctx) {
var post = Post.findById(this.post);
if (!post) return;

return url.resolve(post.path, this.slug);
// PostAsset.path is file path relative to `public_dir`
// no need to urlescape, #1562
return pathFn.join(post.path, this.slug);
});

PostAsset.virtual('source').get(function() {
Expand Down
23 changes: 18 additions & 5 deletions test/scripts/tags/asset_img.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ describe('asset_img', function() {
}).then(function(post_) {
post = post_;

return PostAsset.insert({
_id: 'bar',
slug: 'bar',
post: post._id
});
return Promise.all([
PostAsset.insert({
_id: 'bar',
slug: 'bar',
post: post._id
}),
PostAsset.insert({
_id: 'file with space',
slug: 'file with space',
post: post._id
})
]);
});
});

Expand All @@ -41,6 +48,12 @@ describe('asset_img', function() {
assetImg('bar title').should.eql('<img src="/foo/bar" alt="title" title="title">');
});

it('with space', function() {
// {% asset_img "file with space" "title with space" %}
assetImgTag.call(post, ['file with space', 'title with space'])
.should.eql('<img src="/foo/file with space" alt="title with space" title="title with space">');
});

it('no slug', function() {
should.not.exist(assetImg(''));
});
Expand Down

0 comments on commit 4354260

Please sign in to comment.