summaryrefslogtreecommitdiff
path: root/libappstream-glib
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-07-29 12:37:22 +0100
committerRichard Hughes <richard@hughsie.com>2014-07-29 12:46:20 +0100
commit361ac14eb59c891c46db4e343454ee0b4113fb8a (patch)
tree58fd6de9040e8e4bef4d4e6efca58f7686938535 /libappstream-glib
parent170e4f84c2188109123d22fdd562342d998d5c21 (diff)
downloadappstream-glib-361ac14eb59c891c46db4e343454ee0b4113fb8a.tar.gz
Validate for a sentance case start in <p>, <li>, <name> and <caption> tags
Diffstat (limited to 'libappstream-glib')
-rw-r--r--libappstream-glib/as-app-validate.c65
-rw-r--r--libappstream-glib/as-self-test.c6
2 files changed, 70 insertions, 1 deletions
diff --git a/libappstream-glib/as-app-validate.c b/libappstream-glib/as-app-validate.c
index 5d13bb4..b8c10af 100644
--- a/libappstream-glib/as-app-validate.c
+++ b/libappstream-glib/as-app-validate.c
@@ -33,6 +33,7 @@
#include "as-utils.h"
typedef struct {
+ AsApp *app;
AsAppValidateFlags flags;
GPtrArray *screenshot_urls;
GPtrArray *probs;
@@ -128,6 +129,44 @@ as_app_validate_has_email (const gchar *text)
}
/**
+ * as_app_validate_has_first_word_capital:
+ **/
+static gboolean
+as_app_validate_has_first_word_capital (AsAppValidateHelper *helper, const gchar *text)
+{
+ _cleanup_free_ gchar *first_word = NULL;
+ gchar *tmp;
+ guint i;
+
+ if (text == NULL || text[0] == '\0')
+ return TRUE;
+
+ /* text starts with a number */
+ if (g_ascii_isdigit (text[0]))
+ return TRUE;
+
+ /* get the first word */
+ first_word = g_strdup (text);
+ tmp = g_strstr_len (first_word, -1, " ");
+ if (tmp != NULL)
+ *tmp = '\0';
+
+ /* does the word have caps anywhere? */
+ for (i = 0; first_word[i] != '\0'; i++) {
+ if (first_word[i] >= 'A' && first_word[i] <= 'Z')
+ return TRUE;
+ }
+
+ /* is the first word the project name */
+ if (g_strcmp0 (first_word, as_app_get_id (helper->app)) == 0)
+ return TRUE;
+ if (g_strcmp0 (first_word, as_app_get_name (helper->app, NULL)) == 0)
+ return TRUE;
+
+ return FALSE;
+}
+
+/**
* as_app_validate_description_li:
**/
static void
@@ -164,6 +203,11 @@ as_app_validate_description_li (const gchar *text, AsAppValidateHelper *helper)
AS_PROBLEM_KIND_STYLE_INCORRECT,
"<li> cannot contain a hyperlink");
}
+ if (!as_app_validate_has_first_word_capital (helper, text)) {
+ ai_app_validate_add (helper->probs,
+ AS_PROBLEM_KIND_STYLE_INCORRECT,
+ "<li> requires sentance case");
+ }
}
/**
@@ -219,6 +263,11 @@ as_app_validate_description_para (const gchar *text, AsAppValidateHelper *helper
AS_PROBLEM_KIND_STYLE_INCORRECT,
"<p> cannot contain a hyperlink");
}
+ if (!as_app_validate_has_first_word_capital (helper, text)) {
+ ai_app_validate_add (helper->probs,
+ AS_PROBLEM_KIND_STYLE_INCORRECT,
+ "<p> requires sentance case");
+ }
if (text[str_len - 1] != '.' &&
text[str_len - 1] != '!' &&
text[str_len - 1] != ':') {
@@ -609,6 +658,11 @@ as_app_validate_screenshot (AsScreenshot *ss, AsAppValidateHelper *helper)
AS_PROBLEM_KIND_STYLE_INCORRECT,
"<caption> cannot contain a hyperlink");
}
+ if (!as_app_validate_has_first_word_capital (helper, tmp)) {
+ ai_app_validate_add (helper->probs,
+ AS_PROBLEM_KIND_STYLE_INCORRECT,
+ "<caption> requires sentance case");
+ }
}
}
@@ -875,6 +929,7 @@ as_app_validate (AsApp *app, AsAppValidateFlags flags, GError **error)
}
/* set up networking */
+ helper.app = app;
helper.probs = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
helper.screenshot_urls = g_ptr_array_new_with_free_func (g_free);
helper.flags = flags;
@@ -1096,6 +1151,11 @@ as_app_validate (AsApp *app, AsAppValidateFlags flags, GError **error)
AS_PROBLEM_KIND_STYLE_INCORRECT,
"<name> cannot contain a hyperlink");
}
+ if (!as_app_validate_has_first_word_capital (&helper, name)) {
+ ai_app_validate_add (probs,
+ AS_PROBLEM_KIND_STYLE_INCORRECT,
+ "<name> requires sentance case");
+ }
}
/* comment */
@@ -1122,6 +1182,11 @@ as_app_validate (AsApp *app, AsAppValidateFlags flags, GError **error)
AS_PROBLEM_KIND_STYLE_INCORRECT,
"<summary> cannot contain a hyperlink");
}
+ if (!as_app_validate_has_first_word_capital (&helper, summary)) {
+ ai_app_validate_add (probs,
+ AS_PROBLEM_KIND_STYLE_INCORRECT,
+ "<summary> requires sentance case");
+ }
}
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 e8239cc..32d191c 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -828,7 +828,7 @@ as_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, ==, 24);
+ g_assert_cmpint (probs->len, ==, 26);
as_test_app_validate_check (probs, AS_PROBLEM_KIND_ATTRIBUTE_INVALID,
"<id> has invalid type attribute");
@@ -875,6 +875,10 @@ as_test_app_validate_file_bad_func (void)
"<release> has no version");
as_test_app_validate_check (probs, AS_PROBLEM_KIND_ATTRIBUTE_MISSING,
"<release> has no timestamp");
+ as_test_app_validate_check (probs, AS_PROBLEM_KIND_STYLE_INCORRECT,
+ "<p> requires sentance case");
+ as_test_app_validate_check (probs, AS_PROBLEM_KIND_STYLE_INCORRECT,
+ "<li> requires sentance case");
}
static void