Skip to content

Commit

Permalink
fixed validation of file names
Browse files Browse the repository at this point in the history
  • Loading branch information
cnvogelg committed Nov 24, 2013
1 parent 1c57860 commit 45d36ae
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions amitools/fs/FileName.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def __repr__(self):
def is_root_path_alias(self):
return self.name.get_unicode() in self.root_path_aliases

def has_dir_prefix(self):
return self.name.get_unicode().find("/") != -1

def split_path(self):
pc = self.name.get_unicode().split("/")
p = []
Expand Down Expand Up @@ -55,13 +58,27 @@ def get_upper_ami_str(self):
return result

def is_valid(self):
s = self.name.get_ami_str()
if len(s) > 30:
return False
for c in s:
o = ord(c)
if o == ':' or o == '/':
return False
# check if path contains dir prefix components
if self.has_dir_prefix():
e = self.split_path()
# empty path?
if len(e) == 0:
return False
for p in e:
if not p.is_valid():
return False
return True
else:
# single file name
s = self.name.get_ami_str()
# check for invalid chars
for c in s:
o = ord(c)
if o == ':' or o == '/':
return False
# check max size
if len(s) > 30:
return False
return True

def hash(self, hash_size=72):
Expand Down

0 comments on commit 45d36ae

Please sign in to comment.