zsh-users
 help / color / mirror / code / Atom feed
* Pattern matching operations produces incorrect results when MULTIBYTE is not set
@ 2017-07-01  2:35 guuu
  2017-07-02 17:17 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: guuu @ 2017-07-01  2:35 UTC (permalink / raw)
  To: zsh-users

When MULTIBYTE support turned off, all the indexing and counting of pattern
matching operations becomes wrong.

    unsetopt MULTIBYTE; a=abcdef
(N) (length of matching fragment) returns length of source string despite of
fragment found or not:
    echo ${(N)a#abc} ${(N)a#qwe}
    6 6
(B) and (E) (beginning and end of matching fragment) returns length of source
string +1:
    echo ${(SB)a#b} ${(SE)a#b}
    7 7

Bug is confirmed on current git master version.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Pattern matching operations produces incorrect results when MULTIBYTE is not set
  2017-07-01  2:35 Pattern matching operations produces incorrect results when MULTIBYTE is not set guuu
@ 2017-07-02 17:17 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2017-07-02 17:17 UTC (permalink / raw)
  To: zsh-users

On Fri, 30 Jun 2017 19:35:01 -0700
guuu@secmail.pro wrote:
> When MULTIBYTE support turned off, all the indexing and counting of pattern
> matching operations becomes wrong.

Umm, if I didn't know better I'd think you were saying that was a bad
thing...

This was an oversight when extending the capabilities of a function; the
NO_MULITBYTE case got overlooked.  I've added tests.

pws

diff --git a/Src/utils.c b/Src/utils.c
index acb891d..1b80e8c 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -5417,7 +5417,7 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
     int num, num_in_char, complete;
 
     if (!isset(MULTIBYTE))
-	return ztrlen(ptr);
+	return eptr ? (int)(eptr - ptr) : ztrlen(ptr);
 
     laststart = ptr;
     ret = MB_INVALID;
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index d5798b5..3c93990 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -783,16 +783,36 @@
 0:${(R)...}
 >is the , 
 
+  # Although there's no reliance on multibyte here, the
+  # code exercised is different, so test both paths in the following group.
+  # If the shell isn't multibyte capable the tests are the same;
+  # that's not a problem.
   # This (1) doesn't work with // or /
   #      (2) perhaps ought to be 18, to be consistent with normal zsh
   #          substring indexing and with backreferences.
   print ${(BES)string##white}
+  (unsetopt multibyte; print ${(BES)string##white})
 0:${(BE...)...}
 >14 19
+>14 19
 
   print ${(NS)string##white}
+  (unsetopt multibyte; print ${(NS)string##white})
 0:${(N)...}
 >5
+>5
+
+  fn() {
+    emulate -L zsh
+    local a=abcdef
+    print ${(SNBE)a#abcd}
+    unsetopt multibyte
+    print ${(SNBE)a#abcd}
+  }
+  fn
+0:${(BEN)...} again, with match
+>1 5 4
+>1 5 4
 
   string='abcdefghijklmnopqrstuvwxyz'
   print ${${string%[aeiou]*}/(#m)?(#e)/${(U)MATCH}}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-02 17:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-01  2:35 Pattern matching operations produces incorrect results when MULTIBYTE is not set guuu
2017-07-02 17:17 ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).