@@ -525,6 +525,9 @@ addFlagValue(IspellDict *Conf, char *s, uint32 val)
525
525
Conf -> usecompound = true;
526
526
}
527
527
528
+ /*
529
+ * Import an affix file that follows MySpell or Hunspell format
530
+ */
528
531
static void
529
532
NIImportOOAffixes (IspellDict * Conf , const char * filename )
530
533
{
@@ -685,6 +688,10 @@ NIImportOOAffixes(IspellDict *Conf, const char *filename)
685
688
* import affixes
686
689
*
687
690
* Note caller must already have applied get_tsearch_config_filename
691
+ *
692
+ * This function is responsible for parsing ispell ("old format") affix files.
693
+ * If we realize that the file contains new-format commands, we pass off the
694
+ * work to NIImportOOAffixes(), which will re-read the whole file.
688
695
*/
689
696
void
690
697
NIImportAffixes (IspellDict * Conf , const char * filename )
@@ -763,13 +770,6 @@ NIImportAffixes(IspellDict *Conf, const char *filename)
763
770
764
771
while (* s && t_isspace (s ))
765
772
s += pg_mblen (s );
766
- oldformat = true;
767
-
768
- /* allow only single-encoded flags */
769
- if (pg_mblen (s ) != 1 )
770
- ereport (ERROR ,
771
- (errcode (ERRCODE_CONFIG_FILE_ERROR ),
772
- errmsg ("multibyte flag character is not allowed" )));
773
773
774
774
if (* s == '*' )
775
775
{
@@ -785,26 +785,30 @@ NIImportAffixes(IspellDict *Conf, const char *filename)
785
785
if (* s == '\\' )
786
786
s ++ ;
787
787
788
- /* allow only single-encoded flags */
789
- if (pg_mblen (s ) != 1 )
790
- ereport (ERROR ,
791
- (errcode (ERRCODE_CONFIG_FILE_ERROR ),
792
- errmsg ("multibyte flag character is not allowed" )));
793
-
794
- flag = * (unsigned char * ) s ;
795
- goto nextline ;
796
- }
797
- if (STRNCMP (recoded , "COMPOUNDFLAG" ) == 0 || STRNCMP (recoded , "COMPOUNDMIN" ) == 0 ||
798
- STRNCMP (recoded , "PFX" ) == 0 || STRNCMP (recoded , "SFX" ) == 0 )
799
- {
800
- if (oldformat )
801
- ereport (ERROR ,
802
- (errcode (ERRCODE_CONFIG_FILE_ERROR ),
803
- errmsg ("wrong affix file format for flag" )));
804
- tsearch_readline_end (& trst );
805
- NIImportOOAffixes (Conf , filename );
806
- return ;
788
+ /*
789
+ * An old-format flag is a single ASCII character; we expect it to
790
+ * be followed by EOL, whitespace, or ':'. Otherwise this is a
791
+ * new-format flag command.
792
+ */
793
+ if (* s && pg_mblen (s ) == 1 )
794
+ {
795
+ flag = * (unsigned char * ) s ;
796
+ s ++ ;
797
+ if (* s == '\0' || * s == '#' || * s == '\n' || * s == ':' ||
798
+ t_isspace (s ))
799
+ {
800
+ oldformat = true;
801
+ goto nextline ;
802
+ }
803
+ }
804
+ goto isnewformat ;
807
805
}
806
+ if (STRNCMP (recoded , "COMPOUNDFLAG" ) == 0 ||
807
+ STRNCMP (recoded , "COMPOUNDMIN" ) == 0 ||
808
+ STRNCMP (recoded , "PFX" ) == 0 ||
809
+ STRNCMP (recoded , "SFX" ) == 0 )
810
+ goto isnewformat ;
811
+
808
812
if ((!suffixes ) && (!prefixes ))
809
813
goto nextline ;
810
814
@@ -818,6 +822,16 @@ NIImportAffixes(IspellDict *Conf, const char *filename)
818
822
pfree (pstr );
819
823
}
820
824
tsearch_readline_end (& trst );
825
+ return ;
826
+
827
+ isnewformat :
828
+ if (oldformat )
829
+ ereport (ERROR ,
830
+ (errcode (ERRCODE_CONFIG_FILE_ERROR ),
831
+ errmsg ("affix file contains both old-style and new-style commands" )));
832
+ tsearch_readline_end (& trst );
833
+
834
+ NIImportOOAffixes (Conf , filename );
821
835
}
822
836
823
837
static int
@@ -1436,6 +1450,10 @@ CheckCompoundAffixes(CMPDAffix **ptr, char *word, int len, bool CheckInPlace)
1436
1450
{
1437
1451
bool issuffix ;
1438
1452
1453
+ /* in case CompoundAffix is null: */
1454
+ if (* ptr == NULL )
1455
+ return -1 ;
1456
+
1439
1457
if (CheckInPlace )
1440
1458
{
1441
1459
while ((* ptr )-> affix )
0 commit comments