Skip to content

[Benchmark] Sanitize --save input and strip strip while validating #18073

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion devops/scripts/benchmarks/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,12 @@ def validate_and_parse_env_args(env_args):
)
parser.add_argument(
"--save",
type=str,
type=lambda save: Validate.save_name(
save,
throw=argparse.ArgumentTypeError(
"Specified save name is not within characters [a-zA-Z0-9_-]."
),
),
help="Save the results for comparison under a specified name.",
)
parser.add_argument(
Expand Down
12 changes: 11 additions & 1 deletion devops/scripts/benchmarks/utils/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def validate_on_re(val: str, regex: re.Pattern, throw: Exception = None):
If `throw` argument is not None: return val as-is if val matches regex,
otherwise raise error defined by throw.
"""
is_matching: bool = re.compile(regex).match(val) is not None
is_matching: bool = re.compile(regex).match(val.strip()) is not None

if throw is None:
return is_matching
Expand All @@ -28,6 +28,16 @@ def runner_name(runner_name: str, throw: Exception = None):
"""
return validate_on_re(runner_name, r"^[a-zA-Z0-9_]+$", throw=throw)

@staticmethod
def save_name(save: str, throw: Exception = None):
"""
Returns True if save is within [a-zA-Z0-9_-].

If throw argument is specified: return save as is if save satisfies
aforementioned regex, otherwise raise error defined by throw.
"""
return validate_on_re(save, r"^[a-zA-Z0-9_-]+$", throw=throw)

@staticmethod
def timestamp(t: str, throw: Exception = None):
"""
Expand Down
Loading