Skip to content

Commit

Permalink
input: tighten layer name rules
Browse files Browse the repository at this point in the history
Internally, the empty string is used for the main recipes.  Allowing
path separators in the layer name will probably also blow up. Rule out
both.

Some of the type checks were also missing. Make sure that the layer name
is a string and that a layers entry is a dict if not already a string.
  • Loading branch information
jkloetzke committed Nov 3, 2024
1 parent 6fdeba8 commit c2e6a00
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pym/bob/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -1739,13 +1739,28 @@ def getScm(self):
return self.__scm

class LayerValidator:
@staticmethod
def __validateName(name):
if name == "":
raise schema.SchemaError("Layer name must not be empty")

Check warning on line 1745 in pym/bob/input.py

View check run for this annotation

Codecov / codecov/patch

pym/bob/input.py#L1745

Added line #L1745 was not covered by tests
if any((c in name) for c in '\\/'):
raise schema.SchemaError("Invalid character in layer name")

Check warning on line 1747 in pym/bob/input.py

View check run for this annotation

Codecov / codecov/patch

pym/bob/input.py#L1747

Added line #L1747 was not covered by tests

def validate(self, data):
if isinstance(data,str):
if isinstance(data, str):
self.__validateName(data)
return LayerSpec(data)
elif not isinstance(data, dict):
raise schema.SchemaUnexpectedTypeError("Layer entry must be a string or a dict", None)

Check warning on line 1754 in pym/bob/input.py

View check run for this annotation

Codecov / codecov/patch

pym/bob/input.py#L1754

Added line #L1754 was not covered by tests

if 'name' not in data:
raise schema.SchemaMissingKeyError("Missing 'name' key in {}".format(data), None)
elif not isinstance(data['name'], str):
raise schema.SchemaUnexpectedTypeError("Layer name must be a string", None)

Check warning on line 1759 in pym/bob/input.py

View check run for this annotation

Codecov / codecov/patch

pym/bob/input.py#L1759

Added line #L1759 was not covered by tests

_data = data.copy();
name = _data.get('name')
self.__validateName(name)
del _data['name']

return LayerSpec(name, RecipeSet.LAYERS_SCM_SCHEMA.validate(_data)[0])
Expand Down

0 comments on commit c2e6a00

Please sign in to comment.