Skip to content

Commit

Permalink
fix(listing): add handling of prefix filtering
Browse files Browse the repository at this point in the history
Related to issue #147
  • Loading branch information
Michael Zapata committed Sep 2, 2016
1 parent 4b1288c commit a0674bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/extension/delimiter.extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Delimiter {
this.delimiter = parameters.delimiter;
this.delimLen = this.delimiter ? this.delimiter.length : 0;
this.searchStart = this._getStartIndex(parameters);
this.prefix = parameters.start;
this.maxKeys = checkLimit(parameters.maxKeys, DEFAULT_MAX_KEYS);

this.logger = logger;
Expand Down Expand Up @@ -91,7 +92,9 @@ class Delimiter {
* -> this.delimiter is not present in the key after the prefix
* else
* -> the key is `${this.prefix}${this.delimiter}${objName}`
* @param {String} obj - The key and value of the element
* @param {Object} obj - The key and value of the element
* @param {String} obj.key - The key and value of the element
* @param {String} obj.value - The key and value of the element
* @return {Boolean} - True: Continue, False: Stop
*/
filter(obj) {
Expand All @@ -103,6 +106,9 @@ class Delimiter {
}
const key = obj.key;
const value = obj.value;
if (this.prefix && !key.startsWith(this.prefix)) {
return true;
}
if (this.delimiter) {
const commonPrefixIndex =
key.indexOf(this.delimiter, this.searchStart);
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/extension/delimiter.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ describe('Delimiter extension', () => {
IsTruncated: false,
NextMarker: undefined,
}, (e, input) => e.key > input.start && e.key < input.lt),
new Test('delimiter and prefix (related to #147)', {
delimiter: '/',
start: '/notes/',
}, {
Contents: [receivedData[6]],
CommonPrefixes: ['/notes/spring/', '/notes/summer/'],
Delimiter: '/',
IsTruncated: false,
NextMarker: undefined,
}),
];
tests.forEach(test => {
it(`Should list ${test.name}`, done => {
Expand Down

0 comments on commit a0674bb

Please sign in to comment.