Skip to content
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 validation for custom tag #452

Merged
merged 2 commits into from Dec 22, 2022
Merged

Conversation

JakobDev
Copy link
Contributor

No description provided.

Copy link
Owner

@ximion ximion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments.
It would actually be super nice if you could also add some basic tests for both patches (see for example test_validator_overrides in tests/test-validate.c).
For this particular part of AppStream I don't consider this to be critical, but having tests for new features would certainly be nice, to ensure they continue to work :-)

@@ -921,6 +921,26 @@ AsValidatorIssueTag as_validator_issue_tag_list[] = {
N_("This color is not a valid HTML color code."),
},

{ "custom-invalid-tag",
AS_ISSUE_SEVERITY_ERROR,
N_("The custom tags can only contains value tags"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, any literal should be in backticks so translators don't translate it by accident.


{ "custom-key-missing",
AS_ISSUE_SEVERITY_ERROR,
N_("This custom tag is missing the 'key attribute"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> the `key` attribute

},

{ "custom-value-missing",
AS_ISSUE_SEVERITY_ERROR,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless this causes problems, making this a WARNING or possibly even INFO might be better. That allows some flexibility for writers of custom data (e.g. to have placeholders that are ignored deliberately).

as_validator_check_custom (AsValidator *validator, xmlNode *node)
{
g_autoptr(GHashTable) known_keys = NULL;
known_keys = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This could be one line with the one above it.

continue;

g_autofree gchar *node_content = NULL;
const gchar *node_name;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't mix declarations and statements.

}

gchar *key_name = NULL;
key_name = as_xml_get_prop_value (iter, "key");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a g_autofree

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this here, causes a crash when added to the table. Probably because it is out of scope.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to change the g_hash_table_add line to g_hash_table_add (known_keys, g_steal_pointer (&key_name)); as well for this to work without a crash.

else
g_hash_table_add (known_keys, key_name);

node_content = (gchar*) xmlNodeGetContent (iter);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use either as_xml_get_node_value or as_xml_get_node_value_raw.
You probably want the former and then check for NULL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unfortunately didn't work

node_content =  as_xml_get_node_value (iter);
if (node_content == NULL) {
    as_validator_add_issue (validator, iter, "custom-value-missing", NULL);
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean it did not work?
This code should be fine:

node_content =  as_xml_get_node_value (iter);
if (node_content == NULL || node_content[0] == '\0')
    as_validator_add_issue (validator, iter, "custom-value-missing", NULL);

@ximion
Copy link
Owner

ximion commented Dec 22, 2022

There will be a release today/tomorrow, would be nice to get this into the last release of this year :-)

}

gchar *key_name = NULL;
key_name = as_xml_get_prop_value (iter, "key");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to change the g_hash_table_add line to g_hash_table_add (known_keys, g_steal_pointer (&key_name)); as well for this to work without a crash.

else
g_hash_table_add (known_keys, key_name);

node_content = (gchar*) xmlNodeGetContent (iter);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean it did not work?
This code should be fine:

node_content =  as_xml_get_node_value (iter);
if (node_content == NULL || node_content[0] == '\0')
    as_validator_add_issue (validator, iter, "custom-value-missing", NULL);

@ximion ximion merged commit 789c004 into ximion:master Dec 22, 2022
9 checks passed
ximion added a commit that referenced this pull request Dec 22, 2022
@ximion
Copy link
Owner

ximion commented Dec 22, 2022

Since the release is imminent, I just addressed the issues for you. Kind of an early christmas present ^^
Thank you for the patch, it's useful to have this additional validation!

@JakobDev JakobDev deleted the customvalidate branch January 10, 2023 07:39
@sp1ritCS
Copy link

This patch has seemingly caused applications using the Purism::form_factor custom key in their appstream manifests to fail the appstreamcli validate check, when an application supports more than one form factor. Is this intentional?

https://aplazas.pages.gitlab.gnome.org/blog/blog/2020/10/15/specify-form-factors-in-your-librem-5-apps.html

@ximion
Copy link
Owner

ximion commented Jan 20, 2023

Yes, yikes... The way the keys re used there simply will not work, you can't have two identical keys and assume the values are collected in a list.
So, the validator is correct here.

Maybe simply go the more modern route and set a supported minium display size: https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html#tag-relations-display_length
As well as a supports tag for touch control: https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html#tag-relations-control

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants