-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add image file name validation. #4249
Conversation
add image file name validation.
Changelog(s) in markdown:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! looks good
@@ -295,6 +312,12 @@ def _validate(path: Path) -> None: | |||
raise InvalidXDRCTemplatesFileName | |||
|
|||
|
|||
def _validate_image_file_name(image_name: str): | |||
pattern = r"[^0-9a-zA-Z-_]+" | |||
if re.findall(pattern, image_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think fullmatch
would suit better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fullmatch does not catch the invalid img file names from the unit test case
Co-authored-by: dorschw <81086590+dorschw@users.noreply.github.com>
@@ -283,6 +290,9 @@ def _validate(path: Path) -> None: | |||
): | |||
raise InvalidXSIAMReportFileName | |||
|
|||
if first_level_folder == DOC_FILES_DIR: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if first_level_folder == DOC_FILES_DIR: | |
if first_level_folder == DOC_FILES_DIR and path.suffix in (".png", ".jpg", ".jpeg", ".gif"): |
- Have I missed any suffixes?
- Looks like we call it on all files under
DOC_FILES_DIR
. Please insert this change and then modify the unit tests to match (make sure that it only fails on image files, test it with image suffixes and with non-image and make sure non-image files can contain chars that images are not allowed to).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constant ALLOWED_SUFFIXES support only jpg and svg
add image file name validation.
Related Issues
fixes: https://jira-dc.paloaltonetworks.com/browse/CIAC-5180
Description
Add image file name validation to validate_content_path script