summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--Src/glob.c16
-rw-r--r--Test/D02glob.ztst4
3 files changed, 25 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 705527f52..3f212a535 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-12-21 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
+
+ * 53959+54149: Src/glob.c, Test/D02glob.ztst: when redirecting
+ to/from a pattern (MULTIOS) and if there is no match, issue an
+ error even if NULL_GLOB is in effect.
+
2025-12-16 Oliver Kiddle <opk@zsh.org>
* Christopher Bock: 54148: Completion/Debian/Command/_apt:
diff --git a/Src/glob.c b/Src/glob.c
index 9bfb0f895..e13481955 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -1202,6 +1202,9 @@ checkglobqual(char *str, int sl, int nobareglob, char **sp)
return ret;
}
+/* notify zglob() that it is called from expandredir() */
+static int in_expandredir = 0;
+
/* Main entry point to the globbing code for filename globbing. *
* np points to a node in the list which will be expanded *
* into a series of nodes. */
@@ -1882,6 +1885,14 @@ zglob(LinkList list, LinkNode np, int nountok)
matchct = 1;
}
}
+ else if (in_expandredir) {
+ /* if completing for redirection, we can't remove the pattern
+ * even if NULL_GLOB is in effect */
+ zerr("redirection failed (no match): %s", ostr);
+ zfree(matchbuf, 0);
+ restore_globstate(saved);
+ return;
+ }
if (!(gf_sortlist[0].tp & GS_NONE)) {
/*
@@ -2148,8 +2159,11 @@ xpandredir(struct redir *fn, LinkList redirtab)
/* ...which undergoes all the usual shell expansions */
prefork(&fake, isset(MULTIOS) ? 0 : PREFORK_SINGLE, NULL);
/* Globbing is only done for multios. */
- if (!errflag && isset(MULTIOS))
+ if (!errflag && isset(MULTIOS)) {
+ in_expandredir = 1;
globlist(&fake, 0);
+ in_expandredir = 0;
+ }
if (errflag)
return 0;
if (nonempty(&fake) && !nextnode(firstnode(&fake))) {
diff --git a/Test/D02glob.ztst b/Test/D02glob.ztst
index 1526b6191..33458e3ba 100644
--- a/Test/D02glob.ztst
+++ b/Test/D02glob.ztst
@@ -541,6 +541,10 @@
>No file beginning with z
>Normal string if nullglob not set
+ echo > glob.tmp/nonexistent(N)
+1:redirect to a non-matching pattern is an error even with flag (N)
+?(eval):1: redirection failed (no match): glob.tmp/nonexistent(N)
+
(
setopt extended_glob no_nomatch
cd glob.tmp