more get_unicode_kbinput() fixes: properly discard hexadecimal FFFE to

FFFF instead of xxxE and xxxF, and discard hexadecimal D800 to DFFF as
well, as they're also invalid Unicode characters


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2972 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-08-02 19:54:25 +00:00
parent c25ed534eb
commit b7bf27a509
2 changed files with 23 additions and 20 deletions

View File

@ -263,10 +263,10 @@ CVS code -
as wc does. (DLR) as wc does. (DLR)
- winio.c: - winio.c:
get_word_kbinput() get_word_kbinput()
- Limit the input word to hexadecimal FFFD instead of FFFF, as - Don't allow the input word to be between hexadecimal D800 to
FFFE and FFFF are invalid Unicode characters, rename variables DFFF or hexadecimal FFFE to FFFD, as they are invalid Unicode
word and word_digits to uni and uni_digits, and rename to characters; rename variables word and word_digits to uni and
get_unicode_kbinput(). (DLR) uni_digits; and rename to get_unicode_kbinput(). (DLR)
display_string() display_string()
- Instead of using parse_mbchar()'s bad_chr parameter, use - Instead of using parse_mbchar()'s bad_chr parameter, use
mbrep() to get the representation of a bad character. (DLR) mbrep() to get the representation of a bad character. (DLR)

View File

@ -1232,8 +1232,8 @@ int get_byte_kbinput(int kbinput
} }
/* Translate a Unicode sequence: turn a four-digit hexadecimal number /* Translate a Unicode sequence: turn a four-digit hexadecimal number
* from 0000 to FFFD (case-insensitive) into its corresponding multibyte * from 0000 to D7FF or E000 to FFFD (case-insensitive) into its
* value. */ * corresponding multibyte value. */
int get_unicode_kbinput(int kbinput int get_unicode_kbinput(int kbinput
#ifndef NANO_SMALL #ifndef NANO_SMALL
, bool reset , bool reset
@ -1257,13 +1257,13 @@ int get_unicode_kbinput(int kbinput
switch (uni_digits) { switch (uni_digits) {
case 1: case 1:
/* One digit: reset the Unicode sequence holder and add the /* One digit: reset the Unicode sequence holder and add the
* digit we got to the 4096's position of the Unicode * digit we got to the 0x1000's position of the Unicode
* sequence holder. */ * sequence holder. */
uni = 0; uni = 0;
if ('0' <= kbinput && kbinput <= '9') if ('0' <= kbinput && kbinput <= '9')
uni += (kbinput - '0') * 4096; uni += (kbinput - '0') * 0x1000;
else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f') else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f')
uni += (tolower(kbinput) + 10 - 'a') * 4096; uni += (tolower(kbinput) + 10 - 'a') * 0x1000;
else else
/* If the character we got isn't a hexadecimal digit, or /* If the character we got isn't a hexadecimal digit, or
* if it is and it would put the Unicode sequence out of * if it is and it would put the Unicode sequence out of
@ -1271,12 +1271,14 @@ int get_unicode_kbinput(int kbinput
retval = kbinput; retval = kbinput;
break; break;
case 2: case 2:
/* Two digits: add the digit we got to the 256's position of /* Two digits: add the digit we got to the 0x100's position
* the Unicode sequence holder. */ * of the Unicode sequence holder. */
if ('0' <= kbinput && kbinput <= '9') if (('0' <= kbinput && kbinput <= '7') || (uni != 0xD000 &&
uni += (kbinput - '0') * 256; '8' <= kbinput && kbinput <= '9'))
else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f') uni += (kbinput - '0') * 0x100;
uni += (tolower(kbinput) + 10 - 'a') * 256; else if (uni != 0xd000 && 'a' <= tolower(kbinput) &&
tolower(kbinput) <= 'f')
uni += (tolower(kbinput) + 10 - 'a') * 0x100;
else else
/* If the character we got isn't a hexadecimal digit, or /* If the character we got isn't a hexadecimal digit, or
* if it is and it would put the Unicode sequence out of * if it is and it would put the Unicode sequence out of
@ -1284,12 +1286,12 @@ int get_unicode_kbinput(int kbinput
retval = kbinput; retval = kbinput;
break; break;
case 3: case 3:
/* Three digits: add the digit we got to the 16's position /* Three digits: add the digit we got to the 0x10's position
* of the Unicode sequence holder. */ * of the Unicode sequence holder. */
if ('0' <= kbinput && kbinput <= '9') if ('0' <= kbinput && kbinput <= '9')
uni += (kbinput - '0') * 16; uni += (kbinput - '0') * 0x10;
else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f') else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f')
uni += (tolower(kbinput) + 10 - 'a') * 16; uni += (tolower(kbinput) + 10 - 'a') * 0x10;
else else
/* If the character we got isn't a hexadecimal digit, or /* If the character we got isn't a hexadecimal digit, or
* if it is and it would put the Unicode sequence out of * if it is and it would put the Unicode sequence out of
@ -1303,8 +1305,9 @@ int get_unicode_kbinput(int kbinput
if ('0' <= kbinput && kbinput <= '9') { if ('0' <= kbinput && kbinput <= '9') {
uni += (kbinput - '0'); uni += (kbinput - '0');
retval = uni; retval = uni;
} else if ('a' <= tolower(kbinput) && } else if (('a' <= tolower(kbinput) &&
tolower(kbinput) <= 'd') { tolower(kbinput) <= 'd') || (uni != 0xFFF0 && 'e' <=
tolower(kbinput) && tolower(kbinput) <= 'f')) {
uni += (tolower(kbinput) + 10 - 'a'); uni += (tolower(kbinput) + 10 - 'a');
retval = uni; retval = uni;
} else } else