Skip to content

Commit c1f2cd3

Browse files
committed
Do not validate language tags
Dictionaries named with invalid tags (e.g. “fr-toutesvariantes”) are found in the wild. Pass the problem on to consumers; Enchant should permit these tags.
1 parent 2f26e4c commit c1f2cd3

6 files changed

+14
-89
lines changed

src/enchant.5.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ to decide which spelling provider to use for particular languages.
1919
The per-user file takes precedence.
2020
.PP
2121
The ordering file takes the form \fIlanguage_tag:<comma-separated list of spelling
22-
providers>\fR. The language tag is an IETF BCP 47 language tag, typically of the form \fICOUNTRY_LANGUAGE\fR.
22+
providers>\fR. The language tag is typically an IETF BCP 47 language tag of the form \fICOUNTRY_LANGUAGE\fR.
2323
To see what dictionaries are available, run \fIenchant-lsmod-@ENCHANT_MAJOR_VERSION@\fR. \(oq*\(cq is
2424
used to mean \(lquse this ordering for all languages, unless instructed otherwise.\(rq For example:
2525
.IP

src/lib.c

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,6 @@ enchant_get_conf_dirs (void)
157157
/********************************************************************************/
158158
/********************************************************************************/
159159

160-
/* returns TRUE if tag is valid
161-
* for requires alphanumeric ASCII or underscore
162-
*/
163-
static G_GNUC_PURE int
164-
enchant_is_valid_dictionary_tag(const char * const tag)
165-
{
166-
const char * it;
167-
for (it = tag; *it; ++it)
168-
if(!g_ascii_isalnum(*it) && *it != '_')
169-
return 0;
170-
171-
return it != tag; /*empty tag invalid*/
172-
}
173-
174160
static char *
175161
enchant_normalize_dictionary_tag (const char * const dict_tag)
176162
{
@@ -1015,9 +1001,7 @@ enchant_broker_request_dict_with_pwl (EnchantBroker * broker, const char *const
10151001
enchant_broker_clear_error (broker);
10161002

10171003
char * normalized_tag = enchant_normalize_dictionary_tag (tag);
1018-
if(!enchant_is_valid_dictionary_tag(normalized_tag))
1019-
enchant_broker_set_error (broker, "invalid tag character found");
1020-
else if ((dict = _enchant_broker_request_dict (broker, normalized_tag, pwl)) == NULL)
1004+
if ((dict = _enchant_broker_request_dict (broker, normalized_tag, pwl)) == NULL)
10211005
{
10221006
char * iso_639_only_tag = enchant_iso_639_from_tag (normalized_tag);
10231007
if (iso_639_only_tag == NULL) {
@@ -1088,20 +1072,18 @@ enchant_broker_list_dicts (EnchantBroker * broker, EnchantDictDescribeFn fn, voi
10881072
{
10891073
const char * tag = dicts[i];
10901074
g_debug("tag %s", tag);
1091-
if (enchant_is_valid_dictionary_tag (tag)) {
1092-
GSList *providers = enchant_get_ordered_providers (broker, tag);
1093-
gint this_priority = g_slist_index (providers, provider);
1094-
g_debug("priority %d", this_priority);
1095-
if (this_priority != -1) {
1096-
gint min_priority = this_priority + 1;
1097-
gpointer ptr = g_hash_table_lookup (tag_map, tag);
1098-
if (ptr != NULL)
1099-
min_priority = g_slist_index (providers, ptr);
1100-
if (this_priority < min_priority)
1101-
g_hash_table_insert (tag_map, strdup (tag), provider);
1102-
}
1103-
g_slist_free (providers);
1075+
GSList *providers = enchant_get_ordered_providers (broker, tag);
1076+
gint this_priority = g_slist_index (providers, provider);
1077+
g_debug("priority %d", this_priority);
1078+
if (this_priority != -1) {
1079+
gint min_priority = this_priority + 1;
1080+
gpointer ptr = g_hash_table_lookup (tag_map, tag);
1081+
if (ptr != NULL)
1082+
min_priority = g_slist_index (providers, ptr);
1083+
if (this_priority < min_priority)
1084+
g_hash_table_insert (tag_map, strdup (tag), provider);
11041085
}
1086+
g_slist_free (providers);
11051087
}
11061088

11071089
g_strfreev (dicts);
@@ -1203,9 +1185,7 @@ enchant_broker_dict_exists (EnchantBroker * broker, const char * const tag)
12031185
char * normalized_tag = enchant_normalize_dictionary_tag (tag);
12041186
int exists = 0;
12051187

1206-
if(!enchant_is_valid_dictionary_tag(normalized_tag))
1207-
enchant_broker_set_error (broker, "invalid tag character found");
1208-
else if ((exists = _enchant_broker_dict_exists (broker, normalized_tag)) == 0)
1188+
if ((exists = _enchant_broker_dict_exists (broker, normalized_tag)) == 0)
12091189
{
12101190
char * iso_639_only_tag = enchant_iso_639_from_tag (normalized_tag);
12111191
if (iso_639_only_tag == NULL) {

tests/broker/enchant_broker_dict_exists_tests.i

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,3 @@ TEST_FIXTURE(EnchantBrokerDictExistsTestFixture,
141141
{
142142
CHECK_EQUAL(0, enchant_broker_dict_exists (_broker, ""));
143143
}
144-
145-
TEST_FIXTURE(EnchantBrokerDictExistsTestFixture,
146-
EnchantBrokerDictExists_InvalidTag_0_ErrorSet)
147-
{
148-
CHECK_EQUAL(0, enchant_broker_dict_exists (_broker, "en~US"));
149-
CHECK(NULL != enchant_broker_get_error(_broker));
150-
}

tests/broker/enchant_broker_list_dicts_tests.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,6 @@ struct EnchantBrokerListDictionaries_TestFixture : EnchantBrokerListDictionaries
7979
{ }
8080
};
8181

82-
static char **
83-
InvalidTagEnGbListDictionaries (EnchantProvider *,
84-
size_t * out_n_dicts)
85-
{
86-
*out_n_dicts = 2;
87-
char** out_list = g_new0 (char *, *out_n_dicts + 1);
88-
out_list[0] = g_strdup ("en_GB");
89-
out_list[1] = g_strdup ("en-GB");
90-
91-
return out_list;
92-
}
93-
94-
static void List_Dictionaries_InvalidTag_ProviderConfiguration (EnchantProvider * me, const char *)
95-
{
96-
me->list_dicts=InvalidTagEnGbListDictionaries;
97-
}
98-
99-
struct EnchantBrokerListDictionaries_ProviderReturnsInvalidTag_TestFixture : EnchantBrokerListDictionaries_TestFixtureBase
100-
{
101-
//Setup
102-
EnchantBrokerListDictionaries_ProviderReturnsInvalidTag_TestFixture():
103-
EnchantBrokerListDictionaries_TestFixtureBase(List_Dictionaries_InvalidTag_ProviderConfiguration)
104-
{ }
105-
};
106-
10782

10883
static char **
10984
DuplicateEnGbListDictionaries (EnchantProvider *,
@@ -218,10 +193,3 @@ TEST_FIXTURE(EnchantBrokerListDictionaries_ProviderDuplicateTags_TestFixture,
218193
enchant_broker_list_dicts(_broker, EnchantDictionaryDescribeCallback, &_dictionaryList);
219194
CHECK_EQUAL((unsigned int)1, _dictionaryList.size());
220195
}
221-
222-
TEST_FIXTURE(EnchantBrokerListDictionaries_ProviderReturnsInvalidTag_TestFixture,
223-
EnchantBrokerListDictionaries_ProviderReturnsInvalidTag)
224-
{
225-
enchant_broker_list_dicts(_broker, EnchantDictionaryDescribeCallback, &_dictionaryList);
226-
CHECK_EQUAL((unsigned int)1, _dictionaryList.size());
227-
}

tests/broker/enchant_broker_request_dict_tests.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,6 @@ TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
207207

208208
}
209209

210-
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
211-
EnchantBrokerRequestDictionary_InvalidTag_NULL_ErrorSet)
212-
{
213-
_dict = enchant_broker_request_dict(_broker, "en~US");
214-
CHECK_EQUAL((void*)NULL, _dict);
215-
CHECK(NULL != enchant_broker_get_error(_broker));
216-
}
217-
218210
TEST_FIXTURE(EnchantBrokerTestFixture,
219211
EnchantBrokerRequestDictionary_ProviderLacksListDictionaries_CallbackNeverCalled)
220212
{

tests/broker/enchant_broker_request_dict_with_pwl_tests.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,3 @@ TEST_FIXTURE(EnchantBrokerRequestDictionaryWithPwl_TestFixture,
215215
CHECK(!requestDictionaryCalled);
216216

217217
}
218-
219-
TEST_FIXTURE(EnchantBrokerRequestDictionaryWithPwl_TestFixture,
220-
EnchantBrokerRequestDictionaryWithPwl_InvalidTag_NULL_ErrorSet)
221-
{
222-
_dict = enchant_broker_request_dict_with_pwl(_broker, "en~US", _pwlFileName.c_str());
223-
CHECK_EQUAL((void*)NULL, _dict);
224-
CHECK(NULL != enchant_broker_get_error(_broker));
225-
}

0 commit comments

Comments
 (0)