Skip to content

Commit

Permalink
fixing normalizePath() to properly normalize /.// to / - closes #97
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Aug 3, 2013
1 parent 78a8868 commit a2a999a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -209,6 +209,7 @@ URI.js is published under the [MIT license](http://www.opensource.org/licenses/m

### `[dev-version]` (master branch) ###

* fixing [`.normalizePath()`](http://medialize.github.io/URI.js/docs.html#normalize-path) to properly resolve `/.//` to `/` - ([Issue #97](https://github.com/medialize/URI.js/issues/97))
* fixing [`path()`](http://medialize.github.io/URI.js/docs.html#accessors-pathname) to return empty string if there is no path - ([Issue #82](https://github.com/medialize/URI.js/issues/82))
* fixing crashing of `URI.decodeQuery()` on malformed input - now returns original undecoded data - ([Issue #87](https://github.com/medialize/URI.js/issues/87), [Issue #92](https://github.com/medialize/URI.js/issues/92))
* fixing build tool - ([Issue #83](https://github.com/medialize/URI.js/issues/83))
Expand Down
7 changes: 6 additions & 1 deletion src/URI.js
Expand Up @@ -1576,8 +1576,12 @@ p.normalizePath = function(build) {
_was_relative = true;
_path = '/' + _path;
}

// resolve simples
_path = _path.replace(/(\/(\.\/)+)|\/{2,}/g, '/');
_path = _path
.replace(/(\/(\.\/)+)/g, '/')
.replace(/\/{2,}/g, '/');

// resolve parents
while (true) {
_parent = _path.indexOf('/../');
Expand All @@ -1596,6 +1600,7 @@ p.normalizePath = function(build) {
}
_path = _path.substring(0, _pos) + _path.substring(_parent + 3);
}

// revert to relative
if (_was_relative && this.is('relative')) {
_path = _path.substring(1);
Expand Down
3 changes: 3 additions & 0 deletions test/test.js
Expand Up @@ -904,6 +904,9 @@ test("normalizePath", function() {

u.path('./foo/woo/../bar/baz.html').normalizePath();
equal(u.path(), '/foo/bar/baz.html', "URL: dot-relative parent");

u.path('/.//').normalizePath();
equal(u.path(), '/', "root");

// encoding
u._parts.path = '/~userhome/@mine;is %2F and/';
Expand Down

0 comments on commit a2a999a

Please sign in to comment.