Skip to content

Commit

Permalink
fix(wildcard context matching): Use RFC 3986 path in wildcard match…
Browse files Browse the repository at this point in the history
…ing. (excludes query parameters)
  • Loading branch information
chimurai committed Jun 16, 2016
1 parent 09926cd commit 0ec0e6f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [develop](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.17.0)
- fix(wildcard context matching): Use [RFC 3986 path](https://tools.ietf.org/html/rfc3986#section-3.3) in wildcard matching. (excludes query parameters)

## [v0.16.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.16.0)
- deprecated(proxyTable): renamed `proxyTable` to `router`.
- feat(router): support for custom `router` function.
Expand Down
12 changes: 6 additions & 6 deletions lib/context-matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function matchContext(context, uri, req) {

// custom matching
if (_.isFunction(context)) {
var path = getUrlPath(uri);
var path = getUrl(uri).path;
return context(path, req);
}

Expand All @@ -46,13 +46,13 @@ function matchContext(context, uri, req) {
* @return {Boolean}
*/
function matchSingleStringPath(context, uri) {
var path = getUrlPath(uri);
var path = getUrl(uri).path;
return path.indexOf(context) === 0;
}

function matchSingleGlobPath(pattern, uri) {
var path = getUrlPath(uri);
var matches = micromatch(path, pattern);
var pathname = getUrl(uri).pathname;
var matches = micromatch(pathname, pattern);
return matches && (matches.length > 0);
}

Expand All @@ -75,8 +75,8 @@ function matchMultiPath(contextList, uri) {
return false;
}

function getUrlPath(uri) {
return uri && url.parse(uri).path;
function getUrl(uri) {
return uri && url.parse(uri);
}

function isStringPath(context) {
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": "http-proxy-middleware",
"version": "0.16.0",
"version": "0.17.0-beta",
"description": "The one-liner node.js proxy middleware for connect, express and browser-sync",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/context-matcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ describe('Context Matching', function() {
expect(contextMatcher.match(pattern, 'http://localhost/some/path/index.html')).to.be.false;
});

it('should only match .php files with query params', function() {
expect(contextMatcher.match('/**/*.php', 'http://localhost/a/b/c.php?d=e&e=f')).to.be.false;
expect(contextMatcher.match('/**/*.php?*', 'http://localhost/a/b/c.php?d=e&e=f')).to.be.true;
it('should ignore query params', function() {
expect(contextMatcher.match('/**/*.php', 'http://localhost/a/b/c.php?d=e&e=f')).to.be.true;
expect(contextMatcher.match('/**/*.php?*', 'http://localhost/a/b/c.php?d=e&e=f')).to.be.false;
});

it('should only match any file in root path', function() {
Expand Down

0 comments on commit 0ec0e6f

Please sign in to comment.