From 2b649ba9103839c6ddefe1dae22a795915b6c654 Mon Sep 17 00:00:00 2001 From: dkf Date: Thu, 1 Nov 2007 11:11:42 +0000 Subject: \u0000 is ASCII! [Bug 1808258] --- ChangeLog | 3 +++ generic/tclCmdMZ.c | 24 +++++++++++------------- tests/string.test | 8 ++++---- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index a19a492..0712eba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2007-11-01 Donal K. Fellows + * generic/tclCmdMZ.c (Tcl_StringObjCmd, UniCharIsAscii): Remember, + the NUL character is in ASCII too. [Bug 1808258] + * doc/file.n: Clarified use of [file normalize]. [Bug 1185154] 2007-10-30 Don Porter diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index c241cf3..c1d54ff 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -15,11 +15,13 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCmdMZ.c,v 1.155 2007/10/11 21:35:00 dgp Exp $ + * RCS: @(#) $Id: tclCmdMZ.c,v 1.156 2007/11/01 11:11:44 dkf Exp $ */ #include "tclInt.h" #include "tclRegexp.h" + +static int UniCharIsAscii(int character); /* *---------------------------------------------------------------------- @@ -1489,18 +1491,7 @@ Tcl_StringObjCmd( chcomp = Tcl_UniCharIsAlpha; break; case STR_IS_ASCII: - for (; string1 < end; string1++, failat++) { - /* - * This is a valid check in unicode, because all bytes less - * than 0xC0 are single byte chars (but isascii limits that - * def'n to 0x80). - */ - - if (*((unsigned char *)string1) >= 0x80) { - result = 0; - break; - } - } + chcomp = UniCharIsAscii; break; case STR_IS_BOOL: case STR_IS_TRUE: @@ -2446,6 +2437,13 @@ Tcl_StringObjCmd( return TCL_OK; } +static int +UniCharIsAscii( + int character) +{ + return (character >= 0) && (character < 0x80); +} + /* *---------------------------------------------------------------------- * diff --git a/tests/string.test b/tests/string.test index 8cf93b7..f6c4954 100644 --- a/tests/string.test +++ b/tests/string.test @@ -12,7 +12,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: string.test,v 1.65 2007/10/15 21:27:50 dgp Exp $ +# RCS: @(#) $Id: string.test,v 1.66 2007/11/01 11:11:45 dkf Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -350,11 +350,11 @@ test string-6.17 {string is alpha, unicode} { string is alpha abc\374 } 1 test string-6.18 {string is ascii, true} { - string is ascii abc\u007Fend + string is ascii abc\u007Fend\u0000 } 1 test string-6.19 {string is ascii, false} { - list [string is ascii -fail var abcdef\u0080more] $var -} {0 6} + list [string is ascii -fail var abc\u0000def\u0080more] $var +} {0 7} test string-6.20 {string is boolean, true} { string is boolean true } 1 -- cgit v0.12