zsh-workers
 help / color / mirror / code / Atom feed
From: Martijn Dekker <martijn@inlv.org>
To: zsh-workers@zsh.org
Subject: Bug: [ "(" = ")" ] is true
Date: Wed, 09 Dec 2015 16:34:34 +0100	[thread overview]
Message-ID: <56684A0A.8010404@inlv.org> (raw)

There is a string comparison bug with `[' and `test'; the result is true
if the first string starts with '(' and the second string starts with ')'.

$ [ "(" = ")" ] && echo oops || echo ok
oops
$ [ ")" = "(" ] && echo oops || echo ok
ok
$ [ "((" = "))" ] && echo oops || echo ok
oops
$ [ "((" = ")x" ] && echo oops || echo ok
oops
$ [ "(x" = ")" ] && echo oops || echo ok
oops
$ [ "x(" = ")" ] && echo oops || echo ok
ok
$ [ "(" = "x)" ] && echo oops || echo ok
ok

This appears to be a long-standing bug. I confirmed it in:

zsh 4.3.6
zsh 5.1.1
zsh 5.2

I also found that the bug does *not* exist in zsh 4.1.1.

Also, `[[' does not have this problem.

Credit to /u/tilkau on reddit for discovering this bug:
https://www.reddit.com/r/bash/comments/3w1hm4/how_to_compare_values_to_literal/cxsknzh

Thanks,

- Martijn


             reply	other threads:[~2015-12-09 15:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-09 15:34 Martijn Dekker [this message]
2015-12-09 15:58 ` Stephane Chazelas
2015-12-09 16:31   ` Martijn Dekker
2015-12-09 20:27     ` Bart Schaefer
2015-12-09 16:24 ` Peter Stephenson

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=56684A0A.8010404@inlv.org \
    --to=martijn@inlv.org \
    --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).