Skip to content

Commit

Permalink
Handling None extension properly
Browse files Browse the repository at this point in the history
  • Loading branch information
TheChymera committed Apr 18, 2022
1 parent d91fb98 commit 27bfb55
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tools/schemacode/schemacode/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ def _extension_safety(extension):
* Period safety: https://github.com/bids-standard/bids-specification/issues/1055
* Hopefully this function will be deprecated soon, but it will not break safe entries.
"""
if extension[0] == ".":
extension = extension[1:]
if extension == "None":
return ""
if "*" in extension:
extension = extension.replace(".","\\.")
if "*" in extension:
extension = extension.replace("*",".*?")

Expand All @@ -144,7 +146,7 @@ def _add_extensions(regex_string, variant):
regex_extensions = "({})".format("|".join(fixed_variant_extensions))
else:
regex_extensions = fixed_variant_extensions[0]
regex_string = f"{regex_string}\\.{regex_extensions}"
regex_string = f"{regex_string}{regex_extensions}"

return regex_string

Expand Down Expand Up @@ -213,7 +215,7 @@ def load_top_level(
extension = _extension_safety(extension)
safe_extensions.append(extension)
extensions_regex = "|".join(safe_extensions)
regex = f".*?/{top_level_filename}\\.({extensions_regex})$"
regex = f".*?/{top_level_filename}({extensions_regex})$"
else:
regex = f".*?/{top_level_filename}$"
regex_entry = {
Expand Down Expand Up @@ -658,7 +660,7 @@ def validate_bids(
Can be run from the Bash shell as:
python -c "from schemacode import validator; validator.validate_bids\
('~/.data2/datalad/000026/rawdata', schema_version='{module_path}/data/schema/',\
debug=False)"`
report_path=True, debug=False)"`
"""

if isinstance(bids_paths, str):
Expand Down

0 comments on commit 27bfb55

Please sign in to comment.