From b2734d762f9b33c60575e835bbf9ef190315c79a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 1 Apr 2015 18:55:54 -0400 Subject: [PATCH] glib-compile-schema: Don't accept duplicate docs This schema compiler was completely ignoring and tags. Unfortunately, there are modules out there who merge translations for these back in, with xml:lang. And this is giving dconf-editor a hard time. Since this is not how translations of schemas are meant to be done, just reject such schema files. Also add tests exercising the new error handling. https://bugzilla.gnome.org/show_bug.cgi?id=747209 --- gio/glib-compile-schemas.c | 27 +++++++++++++++++-- gio/tests/Makefile.am | 2 ++ gio/tests/gschema-compile.c | 2 ++ .../description-xmllang.gschema.xml | 13 +++++++++ .../schema-tests/summary-xmllang.gschema.xml | 13 +++++++++ 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 gio/tests/schema-tests/description-xmllang.gschema.xml create mode 100644 gio/tests/schema-tests/summary-xmllang.gschema.xml diff --git a/gio/glib-compile-schemas.c b/gio/glib-compile-schemas.c index e42949b85..4e0604b80 100644 --- a/gio/glib-compile-schemas.c +++ b/gio/glib-compile-schemas.c @@ -192,6 +192,9 @@ typedef struct gboolean checked; GVariant *serialised; + + gboolean summary_seen; + gboolean description_seen; } KeyState; static KeyState * @@ -208,6 +211,8 @@ key_state_new (const gchar *type_string, state->have_gettext_domain = gettext_domain != NULL; state->is_enum = is_enum; state->is_flags = is_flags; + state->summary_seen = FALSE; + state->description_seen = FALSE; if (strinfo) state->strinfo = g_string_new_len (strinfo->str, strinfo->len); @@ -1374,9 +1379,27 @@ start_element (GMarkupParseContext *context, return; } - else if (strcmp (element_name, "summary") == 0 || - strcmp (element_name, "description") == 0) + else if (strcmp (element_name, "summary") == 0) { + if (state->key_state->summary_seen) + g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, + _("Only one <%s> element allowed inside <%s>"), + element_name, container); + state->key_state->summary_seen = TRUE; + + if (NO_ATTRS ()) + state->string = g_string_new (NULL); + return; + } + + else if (strcmp (element_name, "description") == 0) + { + if (state->key_state->description_seen) + g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, + _("Only one <%s> element allowed inside <%s>"), + element_name, container); + state->key_state->description_seen = TRUE; + if (NO_ATTRS ()) state->string = g_string_new (NULL); return; diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am index 3e873bb65..7504ee9a9 100644 --- a/gio/tests/Makefile.am +++ b/gio/tests/Makefile.am @@ -130,6 +130,7 @@ schema_tests = \ default-in-aliases.gschema.xml \ default-not-in-choices.gschema.xml \ default-out-of-range.gschema.xml \ + description-xmllang.gschema.xml \ empty-key.gschema.xml \ enum-with-aliases.gschema.xml \ enum-with-bad-default.gschema.xml \ @@ -180,6 +181,7 @@ schema_tests = \ range-parse-error.gschema.xml \ range-wrong-type.gschema.xml \ range.gschema.xml \ + summary-xmllang.gschema.xml \ wrong-category.gschema.xml \ $(NULL) diff --git a/gio/tests/gschema-compile.c b/gio/tests/gschema-compile.c index 1d3cc19bc..1f2b74654 100644 --- a/gio/tests/gschema-compile.c +++ b/gio/tests/gschema-compile.c @@ -126,6 +126,8 @@ static const SchemaTest tests[] = { { "flags-more-than-one-bit", NULL, "*flags values must have at most 1 bit set*" }, { "flags-with-enum-attr", NULL, "* not (yet) defined*" }, { "flags-with-enum-tag", NULL, "* not (yet) defined*" }, + { "summary-xmllang", NULL, "*Only one element allowed*" }, + { "description-xmllang", NULL, "*Only one element allowed*" }, { "inherit-gettext-domain", NULL, NULL }, { "range-type-test", NULL, NULL }, { "cdata", NULL, NULL } diff --git a/gio/tests/schema-tests/description-xmllang.gschema.xml b/gio/tests/schema-tests/description-xmllang.gschema.xml new file mode 100644 index 000000000..29e771b20 --- /dev/null +++ b/gio/tests/schema-tests/description-xmllang.gschema.xml @@ -0,0 +1,13 @@ + + + + false + Bla + Window-specific screenshot (deprecated) + Captura especifica de finestra (obsoleto) + لقطة شاشة مختصّة بنافذة (مُبطل) + উইন্ডোৰ ক্ষেত্ৰত নিৰ্দিষ্ট স্ক্ৰিনশ্বট (স্খলিত) + Captura específica de ventana (obsoleto) + + + diff --git a/gio/tests/schema-tests/summary-xmllang.gschema.xml b/gio/tests/schema-tests/summary-xmllang.gschema.xml new file mode 100644 index 000000000..a3a867501 --- /dev/null +++ b/gio/tests/schema-tests/summary-xmllang.gschema.xml @@ -0,0 +1,13 @@ + + + + false + Window-specific screenshot (deprecated) + Captura especifica de finestra (obsoleto) + لقطة شاشة مختصّة بنافذة (مُبطل) + উইন্ডোৰ ক্ষেত্ৰত নিৰ্দিষ্ট স্ক্ৰিনশ্বট (স্খলিত) + Captura específica de ventana (obsoleto) + Bla + + +