summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-06-10 16:29:08 +0100
committerRichard Hughes <richard@hughsie.com>2014-06-10 16:29:08 +0100
commit0d9fc343b246b6c7073ba139e8a22f2d2e0c3fe8 (patch)
treed6408a4d700a1936b184e4bea3f7a7b051725288
parent9fbaa4240933dbbf53e34ae517a2021256a92efe (diff)
downloadappstream-glib-0d9fc343b246b6c7073ba139e8a22f2d2e0c3fe8.tar.gz
Fail to validate AppData files with URLs in the descriptions
-rw-r--r--libappstream-glib/as-app-validate.c39
-rw-r--r--libappstream-glib/as-self-test.c4
2 files changed, 39 insertions, 4 deletions
diff --git a/libappstream-glib/as-app-validate.c b/libappstream-glib/as-app-validate.c
index fedde60..5d82e68 100644
--- a/libappstream-glib/as-app-validate.c
+++ b/libappstream-glib/as-app-validate.c
@@ -94,6 +94,21 @@ ai_app_validate_fullstop_ending (const gchar *tmp)
}
/**
+ * as_app_validate_has_hyperlink:
+ **/
+static gboolean
+as_app_validate_has_hyperlink (const gchar *text)
+{
+ if (g_strstr_len (text, -1, "http://") != NULL)
+ return TRUE;
+ if (g_strstr_len (text, -1, "https://") != NULL)
+ return TRUE;
+ if (g_strstr_len (text, -1, "ftp://") != NULL)
+ return TRUE;
+ return FALSE;
+}
+
+/**
* as_app_validate_description_li:
**/
static void
@@ -125,6 +140,11 @@ as_app_validate_description_li (const gchar *text, AsAppValidateHelper *helper)
AS_PROBLEM_KIND_STYLE_INCORRECT,
"<li> cannot end in '.'");
}
+ if (as_app_validate_has_hyperlink (text)) {
+ ai_app_validate_add (helper->probs,
+ AS_PROBLEM_KIND_STYLE_INCORRECT,
+ "<li> cannot contain a hyperlink");
+ }
}
/**
@@ -175,6 +195,11 @@ as_app_validate_description_para (const gchar *text, AsAppValidateHelper *helper
AS_PROBLEM_KIND_STYLE_INCORRECT,
"<p> should not start with 'This application'");
}
+ if (as_app_validate_has_hyperlink (text)) {
+ ai_app_validate_add (helper->probs,
+ AS_PROBLEM_KIND_STYLE_INCORRECT,
+ "<p> cannot contain a hyperlink");
+ }
if (text[str_len - 1] != '.' &&
text[str_len - 1] != '!' &&
text[str_len - 1] != ':') {
@@ -614,9 +639,7 @@ as_app_validate_release (AsRelease *release, AsAppValidateHelper *helper, GError
AS_PROBLEM_KIND_ATTRIBUTE_MISSING,
"<release> has no description");
} else {
- if (g_strstr_len (tmp, -1, "http://") != NULL ||
- g_strstr_len (tmp, -1, "https://") != NULL ||
- g_strstr_len (tmp, -1, "ftp://") != NULL) {
+ if (as_app_validate_has_hyperlink (tmp)) {
ai_app_validate_add (helper->probs,
AS_PROBLEM_KIND_STYLE_INCORRECT,
"<release> description should be "
@@ -953,6 +976,11 @@ as_app_validate (AsApp *app, AsAppValidateFlags flags, GError **error)
AS_PROBLEM_KIND_STYLE_INCORRECT,
"<name> cannot end in '.'");
}
+ if (as_app_validate_has_hyperlink (name)) {
+ ai_app_validate_add (probs,
+ AS_PROBLEM_KIND_STYLE_INCORRECT,
+ "<name> cannot contain a hyperlink");
+ }
}
/* comment */
@@ -974,6 +1002,11 @@ as_app_validate (AsApp *app, AsAppValidateFlags flags, GError **error)
AS_PROBLEM_KIND_STYLE_INCORRECT,
"<summary> cannot end in '.'");
}
+ if (as_app_validate_has_hyperlink (summary)) {
+ ai_app_validate_add (probs,
+ AS_PROBLEM_KIND_STYLE_INCORRECT,
+ "<summary> cannot contain a hyperlink");
+ }
}
if (summary != NULL && name != NULL &&
strlen (summary) < strlen (name)) {
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 90c3a12..e38ecb3 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -575,7 +575,7 @@ ch_test_app_validate_file_bad_func (void)
problem = g_ptr_array_index (probs, i);
g_debug ("%s", as_problem_get_message (problem));
}
- g_assert_cmpint (probs->len, ==, 23);
+ g_assert_cmpint (probs->len, ==, 24);
ch_test_app_validate_check (probs, AS_PROBLEM_KIND_ATTRIBUTE_INVALID,
"<id> has invalid type attribute");
@@ -612,6 +612,8 @@ ch_test_app_validate_file_bad_func (void)
ch_test_app_validate_check (probs, AS_PROBLEM_KIND_STYLE_INCORRECT,
"<p> is too short");
ch_test_app_validate_check (probs, AS_PROBLEM_KIND_STYLE_INCORRECT,
+ "<p> cannot contain a hyperlink");
+ ch_test_app_validate_check (probs, AS_PROBLEM_KIND_STYLE_INCORRECT,
"<release> description should be "
"prose and not contain hyperlinks");
ch_test_app_validate_check (probs, AS_PROBLEM_KIND_ATTRIBUTE_INVALID,