Skip to content

Commit

Permalink
Merge pull request #267 from JordanMilne/patch_path_dot_segment_norma…
Browse files Browse the repository at this point in the history
…lization

fix(normalizePath): handle dot segment normalization edge cases - closes #264
  • Loading branch information
rodneyrehm committed Dec 2, 2015
2 parents f1c14b0 + 13519e6 commit 845dee7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,8 @@
return this;
}

_path = URI.recodePath(_path);

var _was_relative;
var _leadingParents = '';
var _parent, _pos;
Expand Down Expand Up @@ -1847,7 +1849,7 @@

// resolve parents
while (true) {
_parent = _path.indexOf('/..');
_parent = _path.search(/\/\.\.(\/|$)/);
if (_parent === -1) {
// no more ../ to resolve
break;
Expand All @@ -1869,7 +1871,6 @@
_path = _leadingParents + _path.substring(1);
}

_path = URI.recodePath(_path);
this._parts.path = _path;
this.build(!build);
return this;
Expand Down
16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,22 @@
u = URI('/foo/..').normalizePath();
equal(u.path(), '/', 'root /foo/..');

u = URI('/foo/.bar').normalizePath();
equal(u.path(), '/foo/.bar', 'root /foo/.bar');

u = URI('/foo/..bar').normalizePath();
equal(u.path(), '/foo/..bar', 'root /foo/..bar');

// Percent Encoding normalization has to happen before dot segment normalization
u = URI('/foo/%2E%2E').normalizePath();
equal(u.path(), '/', 'root /foo/%2E%2E');

u = URI('/foo/%2E').normalizePath();
equal(u.path(), '/foo/', 'root /foo/%2E');

u = URI('/foo/%2E%2E%2Fbar').normalizePath();
equal(u.path(), '/foo/..%2Fbar', 'root /foo/%2E%2E%2Fbar');

u = URI('../../../../../www/common/js/app/../../../../www_test/common/js/app/views/view-test.html');
u.normalize();
equal(u.path(), '../../../../../www_test/common/js/app/views/view-test.html', 'parent relative');
Expand Down

0 comments on commit 845dee7

Please sign in to comment.