aboutsummaryrefslogtreecommitdiff
From 747d4683221b5584f9663695fb48145689b42ceb Mon Sep 17 00:00:00 2001
From: sebres <info@sebres.de>
Date: Mon, 4 Jan 2021 02:42:38 +0100
Subject: [PATCH] fixes century selector of %ExY and %Exy in datepattern for
 tests, considering interval from 2005 (alternate now) to now; + better
 grouping algorithm for resulting century RE

---
 fail2ban/server/strptime.py | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/fail2ban/server/strptime.py b/fail2ban/server/strptime.py
index 1464a96d1f..39fc795865 100644
--- a/fail2ban/server/strptime.py
+++ b/fail2ban/server/strptime.py
@@ -36,10 +36,30 @@ def _getYearCentRE(cent=(0,3), distance=3, now=(MyTime.now(), MyTime.alternateNo
 	Thereby respect possible run in the test-cases (alternate date used there)
 	"""
 	cent = lambda year, f=cent[0], t=cent[1]: str(year)[f:t]
+	def grp(exprset):
+		c = None
+		if len(exprset) > 1:
+			for i in exprset:
+				if c is None or i[0:-1] == c:
+					c = i[0:-1]
+				else:
+					c = None
+					break
+			if not c:
+				for i in exprset:
+					if c is None or i[0] == c:
+						c = i[0]
+					else:
+						c = None
+						break
+			if c:
+				return "%s%s" % (c, grp([i[len(c):] for i in exprset]))
+		return ("(?:%s)" % "|".join(exprset) if len(exprset[0]) > 1 else "[%s]" % "".join(exprset)) \
+			if len(exprset) > 1 else "".join(exprset)
 	exprset = set( cent(now[0].year + i) for i in (-1, distance) )
 	if len(now) and now[1]:
-		exprset |= set( cent(now[1].year + i) for i in (-1, distance) )
-	return "(?:%s)" % "|".join(exprset) if len(exprset) > 1 else "".join(exprset)
+		exprset |= set( cent(now[1].year + i) for i in xrange(-1, now[0].year-now[1].year+1, distance) )
+	return grp(sorted(list(exprset)))
 
 timeRE = TimeRE()
 
ch.sh, tests/guix-build.sh, tests/guix-daemon.sh, tests/guix-download.sh, tests/guix-environment-container.sh, tests/guix-environment.sh, tests/guix-gc.sh, tests/guix-git-authenticate.sh, tests/guix-graph.sh, tests/guix-hash.sh, tests/guix-home.sh, tests/guix-pack-relocatable.sh, tests/guix-pack.sh, tests/guix-package-aliases.sh, tests/guix-package-net.sh, tests/guix-package.sh, tests/guix-refresh.sh, tests/guix-shell.sh, tests/guix-style.sh, tests/guix-system.sh: Replace uses of '! ...' with '... && false' or `test ! ...` as appropriate. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Eric Bavier 2023-03-26tests: Fix guix-home.sh when guix isn't installed...* tests/guix-home.sh: Reorder NIX_STORE_DIR variable definition to prevent guix from crashing due to missing /gnu/store. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Ting-Wei Lan 2023-01-09home: environment-variables: Fix escaping....* gnu/home/services.scm (environment-variable-shell-definitions): Fix escaping. * tests/guix-home.sh: Add STRING_WITH_ESCAPES environment variable and test its value. Reported-by: elevnkb Andrew Tropin 2023-01-09home: environment-variables: Return support for file-likes and gexps....* gnu/home/services.scm (environment-variable-shell-definitions): Add support for file-likes and gexps. * tests/guix-home.sh: Add SHELL environment variable and test its value. Add BUILDHOSTTIME environment variable. Andrew Tropin 2023-01-05home: services: environment-variables: Add support for literal strings....* gnu/home/services.scm (<literal-string>): New record type. (environment-variable-shell-definitions): Split 'shell-quote' into 'quote-string' and 'shell-double-quote'. Add 'shell-single-quote'. Add clause for 'literal-string' records. * tests/guix-home.sh: Test it. * doc/guix.texi (Essential Home Services): Document it. Ludovic Courtès 2022-08-05tests: Make tests inside container reproducible....* tests/guix-home.sh: Make tests inside container reproducible. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Andrew Tropin 2022-07-14home: services: environment-variables: Double-quote values....Fixes <https://issues.guix.gnu.org/54469>. Reported by Maxime Devos <maximedevos@telenet.be>. * gnu/home/services.scm (environment-variable-shell-definitions): New procedure, with code formerly in 'serialize-posix-env-vars'. (environment-variables->setup-environment-script): Change "setup-environment" from 'mixed-text-file' to 'computed-file', and use 'environment-variable-shell-definitions'. * tests/guix-home.sh: Test it. * gnu/home/services/shells.scm (serialize-posix-env-vars): Delegate to 'environment-variable-shell-definitions'. Ludovic Courtès 2022-07-14home: services: shells: Double-quote environment variable values....Fixes <https://issues.guix.gnu.org/56540>. Until now, environment variable values were emitted unquoted, producing invalid shell code if the value contains spaces for example. * gnu/home/services/shells.scm (serialize-posix-env-vars): Define 'shell-quote' procedure in staged code and use it for #$value. * tests/guix-home.sh: Add test for PS1 variable with a value containing spaces. Ludovic Courtès