mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-04 22:40:12 +01:00
Actually check that bools are valid
The metadata check was omitting booleans and lists, as it was only taking strings. Fix this.
This commit is contained in:
parent
7b575e3fdd
commit
8c2e1fedfc
@ -387,6 +387,8 @@ class FieldValidator():
|
||||
self.matching = matching
|
||||
if type(matching) is str:
|
||||
self.compiled = re.compile(matching)
|
||||
else:
|
||||
self.matching = set(self.matching)
|
||||
self.sep = sep
|
||||
self.fields = fields
|
||||
self.flags = flags
|
||||
@ -394,25 +396,23 @@ class FieldValidator():
|
||||
def _assert_regex(self, values, appid):
|
||||
for v in values:
|
||||
if not self.compiled.match(v):
|
||||
raise MetaDataException("'%s' is not a valid %s in %s. "
|
||||
% (v, self.name, appid) +
|
||||
"Regex pattern: %s" % (self.matching))
|
||||
raise MetaDataException("'%s' is not a valid %s in %s. Regex pattern: %s"
|
||||
% (v, self.name, appid, self.matching))
|
||||
|
||||
def _assert_list(self, values, appid):
|
||||
for v in values:
|
||||
if v not in self.matching:
|
||||
raise MetaDataException("'%s' is not a valid %s in %s. "
|
||||
% (v, self.name, appid) +
|
||||
"Possible values: %s" % (", ".join(self.matching)))
|
||||
raise MetaDataException("'%s' is not a valid %s in %s. Possible values: %s"
|
||||
% (v, self.name, appid, ', '.join(self.matching)))
|
||||
|
||||
def check(self, v, appid):
|
||||
if type(v) is not str or not v:
|
||||
if not v:
|
||||
return
|
||||
if self.sep is not None:
|
||||
values = v.split(self.sep)
|
||||
if type(v) == list:
|
||||
values = v
|
||||
else:
|
||||
values = [v]
|
||||
if type(self.matching) is list:
|
||||
if type(self.matching) is set:
|
||||
self._assert_list(values, appid)
|
||||
else:
|
||||
self._assert_regex(values, appid)
|
||||
@ -444,12 +444,6 @@ valuetypes = {
|
||||
["Litecoin"],
|
||||
[]),
|
||||
|
||||
FieldValidator("bool",
|
||||
r'([Yy]es|[Nn]o|[Tt]rue|[Ff]alse)', None,
|
||||
["Requires Root"],
|
||||
['submodules', 'oldsdkloc', 'forceversion', 'forcevercode',
|
||||
'novcheck']),
|
||||
|
||||
FieldValidator("Repo Type",
|
||||
['git', 'git-svn', 'svn', 'hg', 'bzr', 'srclib'], None,
|
||||
["Repo Type"],
|
||||
@ -857,9 +851,9 @@ def post_metadata_parse(app):
|
||||
build.__dict__[k] = re.sub(esc_newlines, '', v).lstrip().rstrip()
|
||||
elif ftype == TYPE_BOOL:
|
||||
# TODO handle this using <xsd:element type="xsd:boolean> in a schema
|
||||
if isinstance(v, basestring) and v == 'true':
|
||||
build.__dict__[k] = True
|
||||
elif ftype == TYPE_BOOL:
|
||||
if isinstance(v, basestring):
|
||||
build.__dict__[k] = _decode_bool(v)
|
||||
elif ftype == TYPE_STRING:
|
||||
if isinstance(v, bool) and v:
|
||||
build.__dict__[k] = 'yes'
|
||||
|
||||
@ -925,6 +919,18 @@ def _decode_dict(data):
|
||||
return rv
|
||||
|
||||
|
||||
bool_true = re.compile(r'([Yy]es|[Tt]rue)')
|
||||
bool_false = re.compile(r'([Nn]o|[Ff]alse)')
|
||||
|
||||
|
||||
def _decode_bool(s):
|
||||
if bool_true.match(s):
|
||||
return True
|
||||
if bool_false.match(s):
|
||||
return False
|
||||
raise MetaDataException("Invalid bool '%s'" % s)
|
||||
|
||||
|
||||
def parse_metadata(metadatapath):
|
||||
_, ext = common.get_extension(metadatapath)
|
||||
accepted = common.config['accepted_formats']
|
||||
@ -1038,8 +1044,7 @@ def parse_txt_metadata(metadatapath):
|
||||
elif t == TYPE_STRING or t == TYPE_SCRIPT:
|
||||
build.set_flag(pk, pv)
|
||||
elif t == TYPE_BOOL:
|
||||
if pv == 'yes':
|
||||
build.set_flag(pk, True)
|
||||
build.set_flag(pk, _decode_bool(pv))
|
||||
|
||||
def parse_buildline(lines):
|
||||
v = "".join(lines)
|
||||
|
Loading…
Reference in New Issue
Block a user