Skip to content

Commit

Permalink
validator: Ensure developer name and ID are present
Browse files Browse the repository at this point in the history
  • Loading branch information
ximion committed Feb 22, 2024
1 parent 1b8feb9 commit aee22ef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/as-validator-issue-tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,17 +590,17 @@ AsValidatorIssueTag as_validator_issue_tag_list[] = {
"`developer` block instead."),
},

{ "developer-name-has-url",
AS_ISSUE_SEVERITY_WARNING,
{ "developer-info-missing",
AS_ISSUE_SEVERITY_INFO,
/* TRANSLATORS: Please do not translate AppStream tag and property names (in backticks). */
N_("The `name` child of a `developer` block must not contain a hyperlink."),
N_("This component contains no `developer` element with information about its author."),
},

{ "developer-id-missing",
AS_ISSUE_SEVERITY_INFO,
AS_ISSUE_SEVERITY_WARNING,
/* TRANSLATORS: Please do not translate AppStream tag and property names (in backticks). */
N_("The `developer` element is missing an `id` property, containing a unique string ID for the developer. "
"Consider adding a unique ID."),
"Consider adding a unique ID."),
},

{ "developer-id-invalid",
Expand All @@ -609,6 +609,18 @@ AsValidatorIssueTag as_validator_issue_tag_list[] = {
"It must also only contain lowercase ASCII letters, numbers and punctuation."),
},

{ "developer-name-missing",
AS_ISSUE_SEVERITY_WARNING,
/* TRANSLATORS: Please do not translate AppStream tag and property names (in backticks). */
N_("The `developer` block does not have a `name` element with a human-readable project author name."),
},

{ "developer-name-has-url",
AS_ISSUE_SEVERITY_WARNING,
/* TRANSLATORS: Please do not translate AppStream tag and property names (in backticks). */
N_("The `name` child of a `developer` block must not contain a hyperlink."),
},

{ "unknown-desktop-id",
AS_ISSUE_SEVERITY_ERROR,
N_("The set value is not an identifier for a desktop environment as registered with Freedesktop.org."),
Expand Down
20 changes: 20 additions & 0 deletions src/as-validator.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,12 @@ as_validator_add_override (AsValidator *validator,
"tag-empty",
/* allow GNOME to validate metadata using its new versioning scheme (until a better solution is found) */
"releases-not-in-order",
/* very rarely (e.g. for apps like Wine) not having a launchable is actually okay */
"desktop-app-launchable-missing",
/* allowed for a while, as part of the deprecation phase */
"developer-name-tag-deprecated",
/* temporarily allowed to ease transition a bit */
"developer-id-missing",
NULL
};

Expand Down Expand Up @@ -1489,6 +1493,7 @@ static void
as_validator_check_developer (AsValidator *validator, xmlNode *node)
{
g_autofree gchar *devid = NULL;
gboolean developer_name_found = FALSE;

devid = as_xml_get_prop_value (node, "id");
if (devid == NULL) {
Expand Down Expand Up @@ -1522,13 +1527,23 @@ as_validator_check_developer (AsValidator *validator, xmlNode *node)

if (as_str_equal0 (iter->name, "name")) {
g_autofree gchar *content = as_xml_get_node_value (iter);

developer_name_found = TRUE;
if (as_validate_has_hyperlink (content))
as_validator_add_issue (validator,
iter,
"developer-name-has-url",
NULL);
}
}

if (!developer_name_found) {
as_validator_add_issue (validator,
node,
"developer-name-missing",
NULL);

}
}

/**
Expand Down Expand Up @@ -3536,6 +3551,11 @@ as_validator_validate_component_node (AsValidator *validator, AsContext *ctx, xm
}
}

/* check if we had a developer tag */
if (!g_hash_table_contains (found_tags, "developer")) {
as_validator_add_issue (validator, NULL, "developer-info-missing", NULL);
}

as_validator_clear_current_cpt (validator);
return cpt;
}
Expand Down

0 comments on commit aee22ef

Please sign in to comment.