Skip to content

Commit

Permalink
Merge pull request #256 from pinotree/unsigned-char-unicode-check
Browse files Browse the repository at this point in the history
Fix unicode non-ASCII name check with unsigned char
  • Loading branch information
evanmiller authored Nov 17, 2021
2 parents cfdeccf + 3129a92 commit 53c027c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/spss/readstat_sav_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ static readstat_error_t sav_validate_name_chars(const char *name, int unicode) {
if (name[j] == ' ')
return READSTAT_ERROR_NAME_CONTAINS_ILLEGAL_CHARACTER;

if ((name[j] > 0 || !unicode) && name[j] != '@' &&
if (((unsigned char)name[j] < 0x80 || !unicode) && name[j] != '@' &&
name[j] != '.' && name[j] != '_' &&
name[j] != '$' && name[j] != '#' &&
!(name[j] >= 'a' && name[j] <= 'z') &&
Expand All @@ -1246,7 +1246,7 @@ static readstat_error_t sav_validate_name_chars(const char *name, int unicode) {
}
}
char first_char = name[0];
if ((first_char > 0 || !unicode) && first_char != '@' &&
if (((unsigned char)first_char < 0x80 || !unicode) && first_char != '@' &&
!(first_char >= 'a' && first_char <= 'z') &&
!(first_char >= 'A' && first_char <= 'Z')) {
return READSTAT_ERROR_NAME_BEGINS_WITH_ILLEGAL_CHARACTER;
Expand Down
4 changes: 2 additions & 2 deletions src/stata/readstat_dta_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,15 @@ static readstat_error_t dta_validate_name_chars(const char *name, int unicode) {
/* TODO check Unicode class */
int j;
for (j=0; name[j]; j++) {
if ((name[j] > 0 || !unicode) && name[j] != '_' &&
if (((unsigned char)name[j] < 0x80 || !unicode) && name[j] != '_' &&
!(name[j] >= 'a' && name[j] <= 'z') &&
!(name[j] >= 'A' && name[j] <= 'Z') &&
!(name[j] >= '0' && name[j] <= '9')) {
return READSTAT_ERROR_NAME_CONTAINS_ILLEGAL_CHARACTER;
}
}
char first_char = name[0];
if ((first_char > 0 || !unicode) && first_char != '_' &&
if (((unsigned char)first_char < 0x80 || !unicode) && first_char != '_' &&
!(first_char >= 'a' && first_char <= 'z') &&
!(first_char >= 'A' && first_char <= 'Z')) {
return READSTAT_ERROR_NAME_BEGINS_WITH_ILLEGAL_CHARACTER;
Expand Down

0 comments on commit 53c027c

Please sign in to comment.