From 6f126593694f2c714865e7ba16ff6295bf78f697 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 18 May 2012 17:14:38 +0200 Subject: [PATCH] Improve path handling (stripping pairs of dots) --- ports/src/noux/path.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ports/src/noux/path.h b/ports/src/noux/path.h index dcd99d8b71..21e5a045a2 100644 --- a/ports/src/noux/path.h +++ b/ports/src/noux/path.h @@ -90,6 +90,17 @@ namespace Noux { } } + static void strip_superfluous_slashes(char *path) + { + for (; *path; path++) { + if (path[0] != '/') continue; + + /* strip superfluous slashes, e.g., "//path/" -> "/path" */ + while (path[1] == '/') + remove_char(path); + } + } + /** * Find double-dot path element * @@ -126,6 +137,10 @@ namespace Noux { while (cut_start > 0 && path[cut_start - 1] != '/') cut_start--; + /* skip slash in front of the pair of dots */ + if (cut_start > 0) + cut_start--; + strip(path + cut_start, cut_end - cut_start); } } @@ -167,6 +182,7 @@ namespace Noux { { strip_superfluous_dotslashes(_path); strip_double_dot_dirs(_path); + strip_superfluous_slashes(_path); remove_trailing('.', _path); }