diff --git a/check.t b/check.t index c584568..b2f83a8 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.339 2009/11/21 22:30:34 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.340 2009/11/21 22:32:05 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -1361,7 +1361,7 @@ expected-stdout: 4: x . 5: n n . 6: h h . - 7: . + 7: . 8: mä mä . 9: . --- diff --git a/eval.c b/eval.c index 928fec3..ccebf57 100644 --- a/eval.c +++ b/eval.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.71 2009/11/21 22:29:11 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.72 2009/11/21 22:32:08 tg Exp $"); /* * string expansion @@ -1137,7 +1137,7 @@ trimsub(char *str, char *pat, int how) switch (how & 0xFF) { case '#': /* shortest at beginning */ - for (p = str; p <= end; p++) { + for (p = str; p <= end; p += utf_ptradj(p)) { c = *p; *p = '\0'; if (gmatchx(str, pat, false)) { *p = c; @@ -1157,18 +1157,28 @@ trimsub(char *str, char *pat, int how) } break; case '%': /* shortest match at end */ - for (p = end; p >= str; p--) + p = end; + while (p >= str) { + if (gmatchx(p, pat, false)) + goto trimsub_match; + if (UTFMODE) { + char *op = p; + while ((*--p & 0xC0) == 0x80) + ; + if ((p < str) || (p + utf_ptradj(p) != op)) + p = op - 1; + } else + --p; + } + break; + case '%'|0x80: /* longest match at end */ + for (p = str; p <= end; p++) if (gmatchx(p, pat, false)) { trimsub_match: strndupx(end, str, p - str, ATEMP); return (end); } break; - case '%'|0x80: /* longest match at end */ - for (p = str; p <= end; p++) - if (gmatchx(p, pat, false)) - goto trimsub_match; - break; } return (str); /* no match, return string */