Compare commits

...

2 Commits

Author SHA1 Message Date
Richard Hughes c7bcdb7497 Backport a patch from upstream to fix handling unknown tags in AppStream metadata 2024-04-27 02:34:49 +00:00
Mohan Boddu ab93b74d95 Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688
Signed-off-by: Mohan Boddu <mboddu@redhat.com>
2021-08-09 21:15:59 +00:00
3 changed files with 256 additions and 1 deletions

View File

@ -0,0 +1 @@
f01aa02454db76f5907b1d4e65d1f07944df28a9 appstream-glib-0.7.18.tar.xz

View File

@ -0,0 +1,243 @@
diff -Nru appstream-glib-0.7.18/libappstream-glib/as-node.c appstream-glib-0.7.18/libappstream-glib/as-node.c
--- appstream-glib-0.7.18/libappstream-glib/as-node.c 2020-09-07 11:20:43.894573000 +0100
+++ appstream-glib-0.7.18/libappstream-glib/as-node.c 2023-06-07 20:58:11.000000000 +0100
@@ -555,6 +555,8 @@
AsNode *current;
AsNodeFromXmlFlags flags;
const gchar * const *locales;
+ guint8 is_em_text:1;
+ guint8 is_code_text:1;
} AsNodeToXmlHelper;
/**
@@ -604,6 +606,16 @@
AsNode *current;
guint i;
+ /* do not create a child node for em and code tags */
+ if (g_strcmp0 (element_name, "em") == 0) {
+ helper->is_em_text = 1;
+ return;
+ }
+ if (g_strcmp0 (element_name, "code") == 0) {
+ helper->is_code_text = 1;
+ return;
+ }
+
/* check if we should ignore the locale */
data = g_slice_new0 (AsNodeData);
@@ -662,6 +674,53 @@
GError **error)
{
AsNodeToXmlHelper *helper = (AsNodeToXmlHelper *) user_data;
+ AsNodeData *data = helper->current->data;
+
+ /* do not create a child node for em and code tags */
+ if (g_strcmp0 (element_name, "em") == 0) {
+ helper->is_em_text = 0;
+ return;
+ }
+ if (g_strcmp0 (element_name, "code") == 0) {
+ helper->is_code_text = 0;
+ return;
+ }
+
+ if (data->cdata != NULL) {
+ /* split up into lines and add each with spaces stripped */
+ if ((helper->flags & AS_NODE_FROM_XML_FLAG_LITERAL_TEXT) == 0) {
+ AsRefString *cdata = data->cdata;
+ data->cdata = as_node_reflow_text (cdata, strlen (cdata));
+ as_ref_string_unref (cdata);
+ }
+
+ /* intern commonly duplicated tag values and save a bit of memory */
+ if (data->is_tag_valid) {
+ AsNode *root = g_node_get_root (helper->current);
+ switch (data->tag) {
+ case AS_TAG_CATEGORY:
+ case AS_TAG_COMPULSORY_FOR_DESKTOP:
+ case AS_TAG_CONTENT_ATTRIBUTE:
+ case AS_TAG_DEVELOPER_NAME:
+ case AS_TAG_EXTENDS:
+ case AS_TAG_ICON:
+ case AS_TAG_ID:
+ case AS_TAG_KUDO:
+ case AS_TAG_LANG:
+ case AS_TAG_METADATA_LICENSE:
+ case AS_TAG_MIMETYPE:
+ case AS_TAG_PROJECT_GROUP:
+ case AS_TAG_PROJECT_LICENSE:
+ case AS_TAG_SOURCE_PKGNAME:
+ case AS_TAG_URL:
+ as_node_cdata_to_intern (root, data);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
helper->current = helper->current->parent;
}
@@ -693,8 +752,9 @@
if (i >= text_len)
return;
- /* split up into lines and add each with spaces stripped */
- if (data->cdata != NULL) {
+ if (data->cdata != NULL &&
+ g_strcmp0 (as_tag_data_get_name (data), "p") != 0 &&
+ g_strcmp0 (as_tag_data_get_name (data), "li") != 0) {
g_set_error (error,
AS_NODE_ERROR,
AS_NODE_ERROR_INVALID_MARKUP,
@@ -703,37 +763,33 @@
data->cdata, text);
return;
}
- if ((helper->flags & AS_NODE_FROM_XML_FLAG_LITERAL_TEXT) > 0) {
- data->cdata = as_ref_string_new_with_length (text, text_len + 1);
- } else {
- data->cdata = as_node_reflow_text (text, (gssize) text_len);
- }
- /* intern commonly duplicated tag values and save a bit of memory */
- if (data->is_tag_valid && data->cdata != NULL) {
- AsNode *root = g_node_get_root (helper->current);
- switch (data->tag) {
- case AS_TAG_CATEGORY:
- case AS_TAG_COMPULSORY_FOR_DESKTOP:
- case AS_TAG_CONTENT_ATTRIBUTE:
- case AS_TAG_DEVELOPER_NAME:
- case AS_TAG_EXTENDS:
- case AS_TAG_ICON:
- case AS_TAG_ID:
- case AS_TAG_KUDO:
- case AS_TAG_LANG:
- case AS_TAG_METADATA_LICENSE:
- case AS_TAG_MIMETYPE:
- case AS_TAG_PROJECT_GROUP:
- case AS_TAG_PROJECT_LICENSE:
- case AS_TAG_SOURCE_PKGNAME:
- case AS_TAG_URL:
- as_node_cdata_to_intern (root, data);
- break;
- default:
- break;
+ /* support em and code tags */
+ if (helper->is_em_text || helper->is_code_text || data->cdata != NULL) {
+ g_autoptr(GString) str = g_string_new (NULL);
+
+ if (data->cdata != NULL) {
+ g_string_append (str, data->cdata);
+ as_ref_string_unref (data->cdata);
}
+
+ if (helper->is_em_text)
+ g_string_append (str, "<em>");
+ if (helper->is_code_text)
+ g_string_append (str, "<code>");
+
+ g_string_append_len (str, text, text_len);
+
+ if (helper->is_code_text)
+ g_string_append (str, "</code>");
+ if (helper->is_em_text)
+ g_string_append (str, "</em>");
+
+ data->cdata = as_ref_string_new_with_length (str->str, str->len);
+ return;
}
+
+ data->cdata = as_ref_string_new_with_length (text, text_len);
}
static void
@@ -790,7 +846,7 @@
AsNodeFromXmlFlags flags,
GError **error)
{
- AsNodeToXmlHelper helper;
+ AsNodeToXmlHelper helper = {0};
AsNode *root = NULL;
gboolean ret;
g_autoptr(GError) error_local = NULL;
@@ -927,7 +983,7 @@
GCancellable *cancellable,
GError **error)
{
- AsNodeToXmlHelper helper;
+ AsNodeToXmlHelper helper = {0};
GError *error_local = NULL;
AsNode *root = NULL;
const gchar *content_type = NULL;
diff -Nru appstream-glib-0.7.18/libappstream-glib/as-self-test.c appstream-glib-0.7.18/libappstream-glib/as-self-test.c
--- appstream-glib-0.7.18/libappstream-glib/as-self-test.c 2020-09-07 11:20:43.896573000 +0100
+++ appstream-glib-0.7.18/libappstream-glib/as-self-test.c 2023-06-07 20:58:11.000000000 +0100
@@ -2861,6 +2861,20 @@
"<!-- this documents bar -->"
"<bar key=\"value\">baz</bar>"
"</foo>";
+ const gchar *valid_em_code = "<description>"
+ "<p>"
+ "It now also supports <em>em</em> and <code>code</code> tags."
+ "</p>"
+ "</description>";
+ const gchar *valid_em_code_2 = "<description>"
+ "<p><em>Emphasis</em> at the start of the paragraph</p>"
+ "</description>";
+ const gchar *valid_em_code_empty = "<description>"
+ "<p><em></em></p>"
+ "</description>";
+ const gchar *valid_em_code_empty_2 = "<description>"
+ "<p>empty <em></em> emphasis</p>"
+ "</description>";
GError *error = NULL;
AsNode *n2;
AsNode *root;
@@ -2924,6 +2938,43 @@
g_string_free (xml, TRUE);
as_node_unref (root);
+ /* support em and code tags */
+ root = as_node_from_xml (valid_em_code, 0, &error);
+ g_assert_no_error (error);
+ g_assert (root != NULL);
+
+ n2 = as_node_find (root, "description/p");
+ g_assert (n2 != NULL);
+ g_assert_cmpstr (as_node_get_data (n2), ==, "It now also supports <em>em</em> and <code>code</code> tags.");
+ as_node_unref (root);
+
+ root = as_node_from_xml (valid_em_code_2, 0, &error);
+ g_assert_no_error (error);
+ g_assert (root != NULL);
+
+ n2 = as_node_find (root, "description/p");
+ g_assert (n2 != NULL);
+ g_assert_cmpstr (as_node_get_data (n2), ==, "<em>Emphasis</em> at the start of the paragraph");
+ as_node_unref (root);
+
+ root = as_node_from_xml (valid_em_code_empty, 0, &error);
+ g_assert_no_error (error);
+ g_assert (root != NULL);
+
+ n2 = as_node_find (root, "description/p");
+ g_assert (n2 != NULL);
+ g_assert_cmpstr (as_node_get_data (n2), ==, NULL);
+ as_node_unref (root);
+
+ root = as_node_from_xml (valid_em_code_empty_2, 0, &error);
+ g_assert_no_error (error);
+ g_assert (root != NULL);
+
+ n2 = as_node_find (root, "description/p");
+ g_assert (n2 != NULL);
+ g_assert_cmpstr (as_node_get_data (n2), ==, "empty emphasis");
+ as_node_unref (root);
+
/* keep comments */
root = as_node_from_xml (valid,
AS_NODE_FROM_XML_FLAG_KEEP_COMMENTS,

View File

@ -6,11 +6,14 @@
Summary: Library for AppStream metadata
Name: libappstream-glib
Version: 0.7.18
Release: 3%{?dist}
Release: 5%{?dist}
License: LGPLv2+
URL: http://people.freedesktop.org/~hughsient/appstream-glib/
Source0: http://people.freedesktop.org/~hughsient/appstream-glib/releases/appstream-glib-%{version}.tar.xz
# backported from upstream
Patch0: 0001-Improve-handling-of-em-and-code-tags.patch
BuildRequires: glib2-devel >= %{glib2_version}
BuildRequires: docbook-utils
BuildRequires: gtk-doc
@ -131,6 +134,14 @@ from a directory of packages.
%{_mandir}/man1/appstream-builder.1.gz
%changelog
* Fri Apr 26 2024 Richard Hughes <richard@hughsie.com> 0.7.18-5
- Backport a patch from upstream to fix handling unknown tags in AppStream metadata
- Resolves: #RHEL-28856
* Mon Aug 09 2021 Mohan Boddu <mboddu@redhat.com> - 0.7.18-4
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688
* Fri Apr 16 2021 Mohan Boddu <mboddu@redhat.com> - 0.7.18-3
- Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937