Skip to content

Commit 03a25ce

Browse files
committed
Issue a WARNING about invalid rule file format in contrib/unaccent.
We were already issuing a WARNING, albeit only elog not ereport, for duplicate source strings; so warning rather than just being stoically silent seems like the best thing to do here. Arguably both of these complaints should be upgraded to ERRORs, but that might be more behavioral change than people want. Note: the faulty line is already printed via an errcontext hook, so there's no need for more information than these messages provide.
1 parent 1b24887 commit 03a25ce

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

contrib/unaccent/unaccent.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ placeChar(TrieChar *node, const unsigned char *str, int lenstr,
6363
if (lenstr <= 1)
6464
{
6565
if (curnode->replaceTo)
66-
elog(WARNING, "duplicate source strings, first one will be used");
66+
ereport(WARNING,
67+
(errcode(ERRCODE_CONFIG_FILE_ERROR),
68+
errmsg("duplicate source strings, first one will be used")));
6769
else
6870
{
6971
curnode->replacelen = replacelen;
@@ -128,7 +130,7 @@ initTrie(char *filename)
128130
* 2 in whitespace after src
129131
* 3 in trg
130132
* 4 in whitespace after trg
131-
* -1 syntax error detected (line will be ignored)
133+
* -1 syntax error detected
132134
*----------
133135
*/
134136
int state;
@@ -192,6 +194,10 @@ initTrie(char *filename)
192194
rootTrie = placeChar(rootTrie,
193195
(unsigned char *) src, srclen,
194196
trg, trglen);
197+
else if (state < 0)
198+
ereport(WARNING,
199+
(errcode(ERRCODE_CONFIG_FILE_ERROR),
200+
errmsg("invalid syntax: more than two strings in unaccent rule")));
195201

196202
pfree(line);
197203
}

0 commit comments

Comments
 (0)