zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Bart Schaefer <schaefer@brasslantern.com>, zsh-workers@zsh.org
Subject: Re: Fix strftime (prompts) before 5.2?
Date: Sun, 22 Nov 2015 18:06:21 +0000	[thread overview]
Message-ID: <20151122180621.6aa84f81@ntlworld.com> (raw)
In-Reply-To: <151122092711.ZM10012@torch.brasslantern.com>

On Sun, 22 Nov 2015 09:27:11 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> Do we want to try to fix users/20859 ?  It shouldn't be that hard for
> someone in an environment where it fails (I'm having trouble creating
> one).

Putting it all together, the reported failing case is:

% (LC_ALL=de_CH.UTF-8; print -P "%D{%a %b %d} %D{%I:%M:%S%P}")
Son Nov 22 
5:36% (LC_ALL=de_CH.UTF-8; print -P "%D{%a %b %d} %D{%I:%M:%S}")
Son Nov 22 05:37:02

and that's indeed the feature --- no time if %P is present.

The date component is irrelevant (except that it shosw strftime isn't
completely screwed), so it just reduces to the second %D substitution in
that locale.  Not specific to Switzerland or in fact to German; happens
in de_DE.UTF-8 and fr_CH.UTF-8, too.  Suspected metafication, but it
wasn't.

This suggests the test for a successful expansion isn't safe after all,
but probably there aren't too many expansions like %p and %P.

pws

diff --git a/Src/utils.c b/Src/utils.c
index 0afa8c9..4640970 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3143,6 +3143,7 @@ strftimehandling:
 		 * in the accounting in bufsize (but nowhere else).
 		 */
 		{
+		    char origchar = fmt[-1];
 		    int size = fmt - fmtstart;
 		    char *tmp, *last;
 		    tmp = zhalloc(size + 1);
@@ -3163,11 +3164,17 @@ strftimehandling:
 		    *buf = '\1';
 		    if (!strftime(buf, bufsize + 2, tmp, tm))
 		    {
-			if (*buf) {
-			    buf[0] = '\0';
-			    return -1;
+			/*
+			 * Some locales don't have strings for
+			 * AM/PM, so empty output is valid.
+			 */
+			if (*buf || (origchar != 'p' && origchar != 'P')) {
+			    if (*buf) {
+				buf[0] = '\0';
+				return -1;
+			    }
+			    return 0;
 			}
-			return 0;
 		    }
 		    decr = strlen(buf);
 		    buf += decr;


  parent reply	other threads:[~2015-11-22 18:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-22 17:27 Bart Schaefer
2015-11-22 17:43 ` PATCH: ztrftime: more workarounds for broken strftime interface Mikael Magnusson
2015-11-22 18:06 ` Peter Stephenson [this message]
2015-11-22 18:38   ` Fix strftime (prompts) before 5.2? Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151122180621.6aa84f81@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).