Skip to content

Commit

Permalink
validator: Check for nodes that are text nodes even though they shoul…
Browse files Browse the repository at this point in the history
…dn't be
  • Loading branch information
ximion committed Oct 2, 2022
1 parent f45c6a7 commit 4665d91
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/as-validator-issue-tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ AsValidatorIssueTag as_validator_issue_tag_list[] = {
N_("The mentioned tag is empty, which is highly likely not intended as it should have content.")
},

{ "tag-invalid-text-content",
AS_ISSUE_SEVERITY_ERROR,
N_("The mentioned tag has text content, even though it is not allowed to contain text.")
},

{ "cid-is-not-rdns",
AS_ISSUE_SEVERITY_ERROR,
N_("The component ID is required to follow a reverse domain-name scheme for its name. See the AppStream specification for details.")
Expand Down
18 changes: 18 additions & 0 deletions src/as-validator.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,12 +644,29 @@ as_validate_is_secure_url (const gchar *str)
return FALSE;
}

/**
* as_validator_ensure_node_no_text:
*
* Check that the given node has no text content.
**/
static void
as_validator_ensure_node_no_text (AsValidator *validator, xmlNode *node)
{
if (node == NULL)
return;
if (xmlNodeIsText (node) || xmlNodeIsText (node->children))
as_validator_add_issue (validator, node,
"tag-invalid-text-content",
(const gchar*) node->name);
}

/**
* as_validator_check_children_quick:
**/
static void
as_validator_check_children_quick (AsValidator *validator, xmlNode *node, const gchar *allowed_tagname, gboolean allow_empty)
{
as_validator_ensure_node_no_text (validator, node);
for (xmlNode *iter = node->children; iter != NULL; iter = iter->next) {
const gchar *node_name;
/* discard spaces */
Expand Down Expand Up @@ -1350,6 +1367,7 @@ as_validator_check_relations (AsValidator *validator,
GHashTable *known_entries,
AsRelationKind kind)
{
as_validator_ensure_node_no_text (validator, node);
for (xmlNode *iter = node->children; iter != NULL; iter = iter->next) {
const gchar *node_name;
const gchar *rel_dupe_type = NULL;
Expand Down

0 comments on commit 4665d91

Please sign in to comment.