summaryrefslogtreecommitdiffabout
path: root/lib/util.cc
Side-by-side diff
Diffstat (limited to 'lib/util.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/util.cc1
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/util.cc b/lib/util.cc
index 74039c6..069590b 100644
--- a/lib/util.cc
+++ b/lib/util.cc
@@ -1,50 +1,51 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <cassert>
#include <konforka/util.h>
namespace konforka {
/*
* XXX: this code is borrowed from sitecing as is, although it should be optimized.
*/
string normalize_path(const string& p,int o) {
const char *s = p.c_str();
if( s[0]=='.' && s[1]=='/' )
s += 2; // skip leading './'
if(o&strip_leading_slash)
for(;(*s)=='/';s++);
string rv;
string::size_type notslash = 0;
for(;*s;s++) {
if(s[0]=='/') {
if(s[1]=='/')
continue; // skip duplicate slash
if(s[1]=='.' && s[2]=='/') {
// '/./' sequence encountered
s += 2;
continue;
}
}
if(
(o&restrict_dotdot) && (
( rv.empty() && s[0]=='.' && s[1]=='.' && s[2]=='/' ) // '^../'
||
( s[0]=='/' && s[1]=='.' && s[2]=='.' && (s[3]=='/' || s[3]==0) ) // '/../' or '/..$'
)
)
throw restricted_sequence_error(CODEPOINT,"restricted updir (..) sequence encountered");
rv += *s;
if( (*s) !='/' )
notslash = rv.length();
}
if(!(o&strip_trailing_slash))
notslash++;
if(notslash<rv.length())
rv.erase(notslash); // XXX: does this operation have enough sense to be performed?
return rv;
}
string dir_name(const string& p) {
string::size_type sl = p.find_last_of('/');
if(sl==string::npos)