Skip to content
This repository has been archived by the owner on Apr 20, 2019. It is now read-only.

Commit

Permalink
feat: Support Id's which contain dashes (like uuid's) and dots (like …
Browse files Browse the repository at this point in the history
…file names)
  • Loading branch information
Paul Lyons committed Nov 29, 2016
1 parent 1ecddca commit 1a46e0d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/batch.js
Expand Up @@ -164,7 +164,7 @@ internals.buildPath = function (resultsData, pos, parts) {
break;
}

if (!/^[\w:]+$/.test(value)) {
if (!/^([\w:](-?|\.?))+$/.test(value)) {
error = new Error('Reference value includes illegal characters');
break;
}
Expand All @@ -173,6 +173,7 @@ internals.buildPath = function (resultsData, pos, parts) {

}

//console.log("built path:", error ? error : path);
return error ? error : path;
};

Expand Down
33 changes: 33 additions & 0 deletions test/batch.js
Expand Up @@ -203,6 +203,39 @@ describe('Batch', () => {
});
});

it('supports piping Id\'s with "-" (like a uuid) into the next request', (done) => {

Internals.makeRequest(server, '{ "requests": [ {"method": "get", "path": "/interestingIds"}, {"method": "get", "path": "/item/$0.idWithDash"}] }', (res) => {

expect(res.length).to.equal(2);
expect(res[0].idWithDash).to.equal('55cf-687663-55cf687663');
expect(res[1].id).to.equal('55cf-687663-55cf687663');
done();
});
});

it('supports piping interesting Ids with "." (like a filename) into the next request', (done) => {

Internals.makeRequest(server, '{ "requests": [ {"method": "get", "path": "/interestingIds"}, {"method": "get", "path": "/item/$0.idLikeFilename"}] }', (res) => {

expect(res.length).to.equal(2);
expect(res[0].idLikeFilename).to.equal('55cf687663.png');
expect(res[1].id).to.equal('55cf687663.png');
done();
});
});

it('supports piping interesting Ids with "-" and "." (like a filename) into the next request', (done) => {

Internals.makeRequest(server, '{ "requests": [ {"method": "get", "path": "/interestingIds"}, {"method": "get", "path": "/item/$0.idLikeFileNameWithDash"}] }', (res) => {

expect(res.length).to.equal(2);
expect(res[0].idLikeFileNameWithDash).to.equal('55cf-687663-55cf687663.png');
expect(res[1].id).to.equal('55cf-687663-55cf687663.png');
done();
});
});

it('supports piping a deep response into the next request', (done) => {

Internals.makeRequest(server, '{ "requests": [ {"method": "get", "path": "/deepItem"}, {"method": "post", "path": "/echo", "payload": "$0.inner.name"}, {"method": "post", "path": "/echo", "payload": "$0.inner.inner.name"}, {"method": "post", "path": "/echo", "payload": "$0.inner.inner.inner.name"}] }', (res) => {
Expand Down
10 changes: 10 additions & 0 deletions test/internals.js
Expand Up @@ -122,6 +122,15 @@ const redirectHandler = function (request, reply) {
return reply().redirect('/profile');
};

const interestingIdsHandler = function (request, reply) {

return reply({
'idWithDash': '55cf-687663-55cf687663',
'idLikeFilename': '55cf687663.png',
'idLikeFileNameWithDash': '55cf-687663-55cf687663.png'
});
};

const fetch1 = function (request, next) {

next('Hello');
Expand Down Expand Up @@ -182,6 +191,7 @@ module.exports.setupServer = function (done) {
{ method: 'GET', path: '/int', handler: integerHandler },
{ method: 'GET', path: '/int/{id}', handler: integerItemHandler },
{ method: 'GET', path: '/string', handler: stringItemHandler },
{ method: 'GET', path: '/interestingIds', handler: interestingIdsHandler },
{ method: 'GET', path: '/error', handler: errorHandler },
{ method: 'GET', path: '/badchar', handler: badCharHandler },
{ method: 'GET', path: '/badvalue', handler: badValueHandler },
Expand Down

0 comments on commit 1a46e0d

Please sign in to comment.