Skip to content

Commit

Permalink
Merge pull request #2 from evilo/fix/modifiers-collision
Browse files Browse the repository at this point in the history
Modifiers collisions with folder names
  • Loading branch information
saintberry authored Aug 22, 2017
2 parents 8582078 + 42e0719 commit 0c988e8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 16 deletions.
47 changes: 31 additions & 16 deletions src/lib/modifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,24 +176,33 @@ function parseModifiers(mods, modArr) {

switch(mod.desc){
case 'height':
mods.height = string.sanitize(value);
if (mods.height > dimensionLimit) {
mods.height = dimensionLimit;
value = string.sanitize(value);
if (value) {
mods.height = value;
if (mods.height > dimensionLimit) {
mods.height = dimensionLimit;
}
mods.hasModStr = true;
}
mods.hasModStr = true;
break;
case 'width':
mods.width = string.sanitize(value);
if (mods.width > dimensionLimit) {
mods.width = dimensionLimit;
value = string.sanitize(value);
if (value) {
mods.width = value;
if (mods.width > dimensionLimit) {
mods.width = dimensionLimit;
}
mods.hasModStr = true;
}
mods.hasModStr = true;
break;
case 'square':
mods.action = 'square';
mods.height = string.sanitize(value);
mods.width = string.sanitize(value);
mods.hasModStr = true;
value = string.sanitize(value);
if (value) {
mods.action = 'square';
mods.height = value;
mods.width = value;
mods.hasModStr = true;
}
break;
case 'gravity':
value = string.sanitize(value, 'alpha');
Expand All @@ -203,12 +212,18 @@ function parseModifiers(mods, modArr) {
mods.hasModStr = true;
break;
case 'top':
mods.y = string.sanitize(value);
mods.hasModStr = true;
value = string.sanitize(value);
if (value) {
mods.y = value;
mods.hasModStr = true;
}
break;
case 'left':
mods.x = string.sanitize(value);
mods.hasModStr = true;
value = string.sanitize(value);
if (value) {
mods.x = value;
mods.hasModStr = true;
}
break;
case 'crop':
value = string.sanitize(value, 'alpha');
Expand Down
33 changes: 33 additions & 0 deletions test/src/lib/modifiers-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,39 @@ describe('Modifiers module', function(){
});
});

// Is not a real modifier
describe('No modifiers', function(){
it('should not set action to square', function(){
var request = '/stop/path/to/image.jpg';
mod.parse(request).action.should.equal('original');
});

it('should not set action to height', function(){
var request = '/hooops/path/to/image.jpg';
mod.parse(request).action.should.equal('original');
});

it('should not set action to width', function(){
var request = '/wooops/path/to/image.jpg';
mod.parse(request).action.should.equal('original');
});

it('should not set action to top', function(){
var request = '/yooops/path/to/image.jpg';
var p = mod.parse(request);
expect(p.y).to.be.empty;
p.hasModStr.should.equal(false);
});

it('should not set action to left', function(){
var request = '/xooops/path/to/image.jpg';
var p = mod.parse(request);
expect(p.x).to.be.empty;
p.hasModStr.should.equal(false);
});
});



// Gravity
describe('Gravity', function(){
Expand Down

0 comments on commit 0c988e8

Please sign in to comment.