diff --git a/README.md b/README.md index eca4c748..bc764804 100644 --- a/README.md +++ b/README.md @@ -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)) diff --git a/src/URI.js b/src/URI.js index edd7ed3c..e4c26334 100644 --- a/src/URI.js +++ b/src/URI.js @@ -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('/../'); @@ -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); diff --git a/test/test.js b/test/test.js index f39582c3..336f4f7a 100644 --- a/test/test.js +++ b/test/test.js @@ -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/';