diff options
| author | sebres <sebres@users.sourceforge.net> | 2020-04-07 20:05:24 (GMT) |
|---|---|---|
| committer | sebres <sebres@users.sourceforge.net> | 2020-04-07 20:05:24 (GMT) |
| commit | 2227dd53ffef41928d6beedcde35df43cb31bf82 (patch) | |
| tree | 288de443506897402c4d63734624028ca82cc6db | |
| parent | 8bdc1b8e328ecf025cade82185e8d44fdf35a559 (diff) | |
| download | tcl-2227dd53ffef41928d6beedcde35df43cb31bf82.zip tcl-2227dd53ffef41928d6beedcde35df43cb31bf82.tar.gz tcl-2227dd53ffef41928d6beedcde35df43cb31bf82.tar.bz2 | |
fixes [c61818e4c9] for all variants of string trim
| -rw-r--r-- | generic/tclUtil.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c index cf0bdaf..cb5072b 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -1582,14 +1582,17 @@ TrimRight( int bytesLeft = numTrim; pp = Tcl_UtfPrev(p, bytes); - (void)TclUtfToUniChar(pp, &ch1); + (void)TclUtfToUniChar(pp, &ch1); /* Inner loop: scan trim string for match to current character */ do { Tcl_UniChar ch2; int qInc = TclUtfToUniChar(q, &ch2); - if (ch1 == ch2) { + /* compare chars and real length of char, e.g. if TclUtfToUniChar + * mistakenly considers NTS 0-byte as a continuation of invalid utf-8 + * sequence, bug [c61818e4c9] */ + if (ch1 == ch2 && p - pp == qInc) { break; } @@ -1671,12 +1674,17 @@ TrimLeft( const char *q = trim; int bytesLeft = numTrim; + /* take care about real length of char, e.g. if TclUtfToUniChar would + * mistakenly consider NTS 0-byte as a continuation of invalid utf-8 + * sequence, bug [c61818e4c9] */ + if (pInc > numBytes) {pInc = numBytes;} + /* Inner loop: scan trim string for match to current character */ do { Tcl_UniChar ch2; int qInc = TclUtfToUniChar(q, &ch2); - if (ch1 == ch2) { + if (ch1 == ch2 && pInc == qInc) { break; } |
