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
Improve Screenshot validation #450
Conversation
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.
Thanks for the patch! In general those are useful improvements, I just had a few comments on the code itself that need to be addressed before merging this (a rebase on master might also be useful, a lot of previous warnings are now strict errors).
src/as-validator-issue-tag.h
Outdated
|
|
||
| { "screenshot-image-missing-width", | ||
| AS_ISSUE_SEVERITY_ERROR, | ||
| N_("The width property must be present if the type is thumbnail") |
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.
...same for things like width if used as meaning the exact, literal name of a tag or property (put in backticks, add translator hint).
src/as-validator.c
Outdated
|
|
||
| if (iter->type != XML_ELEMENT_NODE) | ||
| continue; | ||
|
|
||
| scr_kind_str = as_xml_get_prop_value (iter, "type"); | ||
| if (g_strcmp0 (scr_kind_str, "default") == 0) | ||
| if (g_strcmp0 (scr_kind_str, "default") == 0) { |
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.
Please don't do this. Use as_screenshot_kind_from_string and check whether as_screenshot_kind_from_string (scr_kind_str) == AS_SCREENSHOT_KIND_DEFAULT (more consistent, easier for refactoring, if you get an UNKNOWN you can already raise a validation warning.
src/as-validator.c
Outdated
| @@ -1257,10 +1264,69 @@ as_validator_check_screenshots (AsValidator *validator, xmlNode *node, AsCompone | |||
| if (iter2->type != XML_ELEMENT_NODE) | |||
| continue; | |||
|
|
|||
| g_autofree gchar *screenshot_width = NULL; | |||
| g_autofree gchar *screenshot_height = NULL; | |||
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.
Please don't add declarations after statements for now...
|
|
||
| image_type = as_xml_get_prop_value (iter2, "type"); | ||
| if (image_type == NULL) | ||
| image_type = "source"; |
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.
Please use as_screenshot_kind_from_string, that will do the right thing here and you get an enum value to compare in the subsequent lines, instead of comparing strings.
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.
This seems to return only if it is default. I did not find a function to check if a type is source or thumbnail
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.
You will need to use as_image_kind_from_string for that
|
There will be a release today/tomorrow, would be nice to get this into the last release of this year :-) |
|
|
||
| image_type = as_xml_get_prop_value (iter2, "type"); | ||
| if (image_type == NULL) | ||
| image_type = "source"; |
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.
You will need to use as_image_kind_from_string for that
|
Can you also rebase this patch on master? Currently it can not be merged easily due to conflicts. |
|
I merged this and fixed all mentioned issues in a follow-up commit. Thank you for the patch! |
I added the following checks:
sourceandthumbnailare the only allowed values for a Image typethumbnail, it must have 'width' and 'height'sourceper language is allowed for each Screenshot