Skip to content

Commit

Permalink
prevent too long path
Browse files Browse the repository at this point in the history
  • Loading branch information
sbcgua committed Feb 22, 2020
1 parent 34c10f8 commit c52b666
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function parsePathParams({pathParameters}) {
if (!pathParameters.sourcePath) throw Error('Unexpected source path');
const segments = pathParameters.sourcePath.split('/').filter(s => s !== '');
if (segments.length === 0) throw Error('Unexpected path');
if (segments.length > 20) throw Error('Too many path segments');

const STATES = enumify(['TYPE', 'OWNER', 'REPO', 'FILE', 'ATTR', 'END']);
let expected = STATES.TYPE;
Expand Down
7 changes: 7 additions & 0 deletions lib/params.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ describe('Regular Parser tests', () => {
},
})).toThrow('Unexpect path segment');
});
test('should throw on too long path', () => {
expect(() => parsePathParams({
pathParameters: {
sourcePath: new Array(21).fill('a').join('/'),
},
})).toThrow('Too many path segments');
});
});

describe('apack Parser tests', () => {
Expand Down

0 comments on commit c52b666

Please sign in to comment.