mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-27 09:36:53 +02:00
glib-compile-schema: Don't accept duplicate docs
This schema compiler was completely ignoring <summary> and <description> 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
This commit is contained in:
parent
6ba363b619
commit
b2734d762f
@ -192,6 +192,9 @@ typedef struct
|
|||||||
|
|
||||||
gboolean checked;
|
gboolean checked;
|
||||||
GVariant *serialised;
|
GVariant *serialised;
|
||||||
|
|
||||||
|
gboolean summary_seen;
|
||||||
|
gboolean description_seen;
|
||||||
} KeyState;
|
} KeyState;
|
||||||
|
|
||||||
static KeyState *
|
static KeyState *
|
||||||
@ -208,6 +211,8 @@ key_state_new (const gchar *type_string,
|
|||||||
state->have_gettext_domain = gettext_domain != NULL;
|
state->have_gettext_domain = gettext_domain != NULL;
|
||||||
state->is_enum = is_enum;
|
state->is_enum = is_enum;
|
||||||
state->is_flags = is_flags;
|
state->is_flags = is_flags;
|
||||||
|
state->summary_seen = FALSE;
|
||||||
|
state->description_seen = FALSE;
|
||||||
|
|
||||||
if (strinfo)
|
if (strinfo)
|
||||||
state->strinfo = g_string_new_len (strinfo->str, strinfo->len);
|
state->strinfo = g_string_new_len (strinfo->str, strinfo->len);
|
||||||
@ -1374,9 +1379,27 @@ start_element (GMarkupParseContext *context,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp (element_name, "summary") == 0 ||
|
else if (strcmp (element_name, "summary") == 0)
|
||||||
strcmp (element_name, "description") == 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 ())
|
if (NO_ATTRS ())
|
||||||
state->string = g_string_new (NULL);
|
state->string = g_string_new (NULL);
|
||||||
return;
|
return;
|
||||||
|
@ -130,6 +130,7 @@ schema_tests = \
|
|||||||
default-in-aliases.gschema.xml \
|
default-in-aliases.gschema.xml \
|
||||||
default-not-in-choices.gschema.xml \
|
default-not-in-choices.gschema.xml \
|
||||||
default-out-of-range.gschema.xml \
|
default-out-of-range.gschema.xml \
|
||||||
|
description-xmllang.gschema.xml \
|
||||||
empty-key.gschema.xml \
|
empty-key.gschema.xml \
|
||||||
enum-with-aliases.gschema.xml \
|
enum-with-aliases.gschema.xml \
|
||||||
enum-with-bad-default.gschema.xml \
|
enum-with-bad-default.gschema.xml \
|
||||||
@ -180,6 +181,7 @@ schema_tests = \
|
|||||||
range-parse-error.gschema.xml \
|
range-parse-error.gschema.xml \
|
||||||
range-wrong-type.gschema.xml \
|
range-wrong-type.gschema.xml \
|
||||||
range.gschema.xml \
|
range.gschema.xml \
|
||||||
|
summary-xmllang.gschema.xml \
|
||||||
wrong-category.gschema.xml \
|
wrong-category.gschema.xml \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
@ -126,6 +126,8 @@ static const SchemaTest tests[] = {
|
|||||||
{ "flags-more-than-one-bit", NULL, "*flags values must have at most 1 bit set*" },
|
{ "flags-more-than-one-bit", NULL, "*flags values must have at most 1 bit set*" },
|
||||||
{ "flags-with-enum-attr", NULL, "*<enum id='flags'> not (yet) defined*" },
|
{ "flags-with-enum-attr", NULL, "*<enum id='flags'> not (yet) defined*" },
|
||||||
{ "flags-with-enum-tag", NULL, "*<flags id='flags'> not (yet) defined*" },
|
{ "flags-with-enum-tag", NULL, "*<flags id='flags'> not (yet) defined*" },
|
||||||
|
{ "summary-xmllang", NULL, "*Only one <summary> element allowed*" },
|
||||||
|
{ "description-xmllang", NULL, "*Only one <description> element allowed*" },
|
||||||
{ "inherit-gettext-domain", NULL, NULL },
|
{ "inherit-gettext-domain", NULL, NULL },
|
||||||
{ "range-type-test", NULL, NULL },
|
{ "range-type-test", NULL, NULL },
|
||||||
{ "cdata", NULL, NULL }
|
{ "cdata", NULL, NULL }
|
||||||
|
13
gio/tests/schema-tests/description-xmllang.gschema.xml
Normal file
13
gio/tests/schema-tests/description-xmllang.gschema.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<schemalist>
|
||||||
|
<schema path="/org/gnome/gnome-screenshot/" id="org.gnome.gnome-screenshot">
|
||||||
|
<key type="b" name="take-window-shot">
|
||||||
|
<default>false</default>
|
||||||
|
<summary>Bla</summary>
|
||||||
|
<description>Window-specific screenshot (deprecated)</description>
|
||||||
|
<description xml:lang="an">Captura especifica de finestra (obsoleto)</description>
|
||||||
|
<description xml:lang="ar">لقطة شاشة مختصّة بنافذة (مُبطل)</description>
|
||||||
|
<description xml:lang="as">উইন্ডোৰ ক্ষেত্ৰত নিৰ্দিষ্ট স্ক্ৰিনশ্বট (স্খলিত)</description>
|
||||||
|
<description xml:lang="ast">Captura específica de ventana (obsoleto)</description>
|
||||||
|
</key>
|
||||||
|
</schema>
|
||||||
|
</schemalist>
|
13
gio/tests/schema-tests/summary-xmllang.gschema.xml
Normal file
13
gio/tests/schema-tests/summary-xmllang.gschema.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<schemalist>
|
||||||
|
<schema path="/org/gnome/gnome-screenshot/" id="org.gnome.gnome-screenshot">
|
||||||
|
<key type="b" name="take-window-shot">
|
||||||
|
<default>false</default>
|
||||||
|
<summary>Window-specific screenshot (deprecated)</summary>
|
||||||
|
<summary xml:lang="an">Captura especifica de finestra (obsoleto)</summary>
|
||||||
|
<summary xml:lang="ar">لقطة شاشة مختصّة بنافذة (مُبطل)</summary>
|
||||||
|
<summary xml:lang="as">উইন্ডোৰ ক্ষেত্ৰত নিৰ্দিষ্ট স্ক্ৰিনশ্বট (স্খলিত)</summary>
|
||||||
|
<summary xml:lang="ast">Captura específica de ventana (obsoleto)</summary>
|
||||||
|
<description>Bla</description>
|
||||||
|
</key>
|
||||||
|
</schema>
|
||||||
|
</schemalist>
|
Loading…
x
Reference in New Issue
Block a user