Skip to content

Commit

Permalink
Merge pull request #35 from maruware/fix-rename-src-with-query-bug
Browse files Browse the repository at this point in the history
Fix error on renaming asset src with query
  • Loading branch information
inlife authored May 15, 2017
2 parents 93561b9 + e82270e commit 9867ef1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"async": "^2.0.0-rc.6",
"body-parser": "^1.15.0",
"cli": "^1.0.0",
"download": "^5.0.2",
"download": "^6.1.0",
"express": "^4.13.4",
"fs-extra": "^0.30.0",
"jimp": "^0.2.21",
Expand Down
3 changes: 2 additions & 1 deletion renderer/tasks/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const fs = require('fs-extra');
const path = require('path');
const url = require('url');
const async = require('async');

/**
Expand All @@ -18,7 +19,7 @@ module.exports = function(project) {

// iterate over each file and create rename(move) callback
for (let asset of project.assets) {
let src = path.join( project.workpath, asset.src.substring( asset.src.lastIndexOf('/') + 1 ));
let src = path.join( project.workpath, path.basename(url.parse(asset.src).pathname));
let dst = path.join( project.workpath, asset.name );

if (src === dst) continue;
Expand Down
9 changes: 9 additions & 0 deletions test/renderer/tasks/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('Task: rename', () => {
beforeEach(() => {
fs.writeFileSync( path.join('test', 'file1src') );
fs.writeFileSync( path.join('test', 'file2src') );
fs.writeFileSync( path.join('test', 'file3src') );

project = {
workpath: 'test',
Expand All @@ -30,21 +31,27 @@ describe('Task: rename', () => {
}, {
src: 'url/file2src',
name: 'file2dst'
}, {
src: 'url/file3src?q=test',
name: 'file3dst'
}]
}
});

afterEach(() => {
fs.removeSync( path.join('test', 'file1src') );
fs.removeSync( path.join('test', 'file2src') );
fs.removeSync( path.join('test', 'file3src') );
fs.removeSync( path.join('test', 'file1dst') );
fs.removeSync( path.join('test', 'file2dst') );
fs.removeSync( path.join('test', 'file3dst') );
})

it('should rename each asset file to asset.name', (done) => {
rename(project).should.be.fulfilled.then(() => {
path.join('test', 'file1dst').should.be.a.path();
path.join('test', 'file2dst').should.be.a.path();
path.join('test', 'file3dst').should.be.a.path();
}).should.notify(done);
});

Expand All @@ -54,6 +61,7 @@ describe('Task: rename', () => {
rename(project).should.be.fulfilled.then(() => {
path.join('test', 'file1src').should.be.a.path();
path.join('test', 'file2dst').should.be.a.path();
path.join('test', 'file3dst').should.be.a.path();
}).should.notify(done);
});

Expand All @@ -63,6 +71,7 @@ describe('Task: rename', () => {
rename(project).should.be.fulfilled.then(() => {
path.join('test', 'file1dst').should.be.a.path();
path.join('test', 'file2dst').should.be.a.path();
path.join('test', 'file3dst').should.be.a.path();
}).should.notify(done);
});
});

0 comments on commit 9867ef1

Please sign in to comment.