Skip to content

Commit

Permalink
* Fixed util buildPath leaking index state
Browse files Browse the repository at this point in the history
 * Added supporting tests
  • Loading branch information
kfitzgerald committed May 24, 2019
1 parent d15306b commit 341cf0c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

When stuff changes, it's described here.

## 2.1.0
* Fixed util buildPath leaking index state

## 2.2.0
* Set Host header on HTTP requests

Expand Down
2 changes: 1 addition & 1 deletion dist/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function Client(config) {
/**
* SDK Version
*/
Client.Version = '2.2.0';
Client.Version = '2.2.1';

/**
* Expose the Provider base class
Expand Down
8 changes: 4 additions & 4 deletions dist/okanjo-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,6 @@ function copy(destination, source) {
}


var extractParams = /\{([a-zA-Z_]+)}/g;

/**
* Builds the final URL path given replaceable param names
* @param {string} path - Route path
Expand All @@ -560,7 +558,9 @@ var extractParams = /\{([a-zA-Z_]+)}/g;
*/
function buildPath(path, params) {

var resultPath = path, p, token, name;
var extractParams = /\{([a-zA-Z_]+)}/g,
resultPath = path,
p, token, name;

// Pull out the expected parameters
while ((p = extractParams.exec(path)) !== null) {
Expand Down Expand Up @@ -1742,7 +1742,7 @@ function Client(config) {
/**
* SDK Version
*/
Client.Version = '2.2.0';
Client.Version = '2.2.1';

/**
* Expose the Provider base class
Expand Down
4 changes: 2 additions & 2 deletions dist/okanjo-sdk.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/okanjo-sdk.min.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ function copy(destination, source) {
}


var extractParams = /\{([a-zA-Z_]+)}/g;

/**
* Builds the final URL path given replaceable param names
* @param {string} path - Route path
Expand All @@ -73,7 +71,9 @@ var extractParams = /\{([a-zA-Z_]+)}/g;
*/
function buildPath(path, params) {

var resultPath = path, p, token, name;
var extractParams = /\{([a-zA-Z_]+)}/g,
resultPath = path,
p, token, name;

// Pull out the expected parameters
while ((p = extractParams.exec(path)) !== null) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "okanjo",
"version": "2.2.0",
"version": "2.2.1",
"description": "Integrate your application with the Okanjo API.",
"main": "dist/client.js",
"scripts": {
Expand Down
17 changes: 17 additions & 0 deletions test/util_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,21 @@ describe('Utilities', function() {
res.message.should.match(/Path parameter .* required/);

});

it('should return an error and then success (no regex leak)', () => {
const path = '/accounts/{accountId}/sessions/{sessionId}';

const res = Util.buildPath(path, {accountId: 'ac_123'});

res.should.be.instanceof(Error);
res.message.should.match(/Path parameter .* required/);

const path2 = '/products/{product_id}';

const res2 = Util.buildPath(path2, {product_id: 'product_dev_12n3j123123'});

res2.should.equal('/products/product_dev_12n3j123123');


});
});

0 comments on commit 341cf0c

Please sign in to comment.