From 578e2b5c138f950bdc7dcc815ab7faa7b0598ded Mon Sep 17 00:00:00 2001 From: JakobDev Date: Fri, 3 Jun 2022 12:02:11 +0200 Subject: [PATCH 1/2] Check if URL type is redefined --- src/as-validator-issue-tag.h | 6 ++++++ src/as-validator.c | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/as-validator-issue-tag.h b/src/as-validator-issue-tag.h index dce04326..6c0621ff 100644 --- a/src/as-validator-issue-tag.h +++ b/src/as-validator-issue-tag.h @@ -442,6 +442,12 @@ AsValidatorIssueTag as_validator_issue_tag_list[] = { N_("Invalid `type` property for this `url` tag. URLs of this type are not known in the AppStream specification."), }, + { "url-type-redefined", + AS_ISSUE_SEVERITY_WARNING, + /* TRANSLATORS: Please do not translate AppStream tag and property names (in backticks). */ + N_("This relation item has already been defined."), + }, + { "url-not-reachable", AS_ISSUE_SEVERITY_WARNING, N_("Unable to reach remote location that this URL references - does it exist?"), diff --git a/src/as-validator.c b/src/as-validator.c index 41ccfb05..3ac3c013 100644 --- a/src/as-validator.c +++ b/src/as-validator.c @@ -1881,6 +1881,7 @@ as_validator_validate_component_node (AsValidator *validator, AsContext *ctx, xm g_autofree gchar *cpttype = NULL; g_autoptr(GHashTable) found_tags = NULL; g_autoptr(GHashTable) known_relation_items = NULL; + g_autoptr(GHashTable) known_url_types = NULL; g_autofree gchar *date_eol_str = NULL; AsFormatStyle mode; @@ -1889,6 +1890,7 @@ as_validator_validate_component_node (AsValidator *validator, AsContext *ctx, xm /* hash tables for finding duplicates */ found_tags = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); known_relation_items = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + known_url_types = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); mode = as_context_get_style (ctx); @@ -2050,6 +2052,13 @@ as_validator_validate_component_node (AsValidator *validator, AsContext *ctx, xm node_content, "url-not-reachable"); + if (g_hash_table_lookup (known_url_types, prop) == NULL) { + g_hash_table_insert (known_url_types, g_strdup(prop), g_strdup("")); + } + else { + as_validator_add_issue (validator, iter, "url-type-redefined", prop); + } + } else if (g_strcmp0 (node_name, "categories") == 0) { as_validator_check_appear_once (validator, iter, found_tags); as_validator_check_children_quick (validator, iter, "category", FALSE); From 7b4f6a08e5961889fd8a5dad7bc58caebf439662 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Fri, 3 Jun 2022 12:28:47 +0200 Subject: [PATCH 2/2] Fix crash when prop does not exists --- src/as-validator.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/as-validator.c b/src/as-validator.c index 3ac3c013..d824ad17 100644 --- a/src/as-validator.c +++ b/src/as-validator.c @@ -2052,11 +2052,13 @@ as_validator_validate_component_node (AsValidator *validator, AsContext *ctx, xm node_content, "url-not-reachable"); - if (g_hash_table_lookup (known_url_types, prop) == NULL) { - g_hash_table_insert (known_url_types, g_strdup(prop), g_strdup("")); - } - else { - as_validator_add_issue (validator, iter, "url-type-redefined", prop); + if (prop) { + if (g_hash_table_lookup (known_url_types, prop) == NULL) { + g_hash_table_insert (known_url_types, g_strdup(prop), g_strdup("")); + } + else { + as_validator_add_issue (validator, iter, "url-type-redefined", prop); + } } } else if (g_strcmp0 (node_name, "categories") == 0) {