From bfbbd973240392cfde8cd1b93c1b17dd9fc1a917 Mon Sep 17 00:00:00 2001 From: joffrey-b Date: Tue, 21 Apr 2026 11:45:50 +0200 Subject: [PATCH] Added restrictions for separators --- docs/src/content/docs/reference/configuration.md | 2 +- internal/cfg/cfg.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/src/content/docs/reference/configuration.md b/docs/src/content/docs/reference/configuration.md index 427663d..f0f701a 100644 --- a/docs/src/content/docs/reference/configuration.md +++ b/docs/src/content/docs/reference/configuration.md @@ -28,7 +28,7 @@ If the environment variable is defined without **and** with the suffix at the sa - Description: The lowercase name of the default theme to be used by the client. Overridden if a user picks a theme in the theme switcher. ##### KOITO_DATE_FORMAT - Default: `Browser locale` -- Description: The format to use for dates in the client. Supports the tokens `DD`, `MM`, and `YYYY` with any separator. For example, `DD/MM/YYYY` produces `21/04/2026`. When not set, dates are formatted using the browser's locale. +- Description: The format to use for dates in the client. Supports the tokens `DD`, `MM`, and `YYYY` with `/`, `-`, and `.`as separators. For example, `DD/MM/YYYY` produces `21/04/2026`. When not set, dates are formatted using the browser's locale. ##### KOITO_LOGIN_GATE - Default: `false` - Description: When `true`, Koito will not show any statistics unless the user is logged in. diff --git a/internal/cfg/cfg.go b/internal/cfg/cfg.go index ced0770..4fdc57f 100644 --- a/internal/cfg/cfg.go +++ b/internal/cfg/cfg.go @@ -188,7 +188,14 @@ func loadConfig(getenv func(string) string, version string) (*config, error) { } cfg.defaultTheme = getenv(DEFAULT_THEME_ENV) - cfg.dateFormat = getenv(DATE_FORMAT_ENV) + rawDateFormat := getenv(DATE_FORMAT_ENV) + if rawDateFormat != "" { + validFormat := regexp.MustCompile(`^(DD|MM|YYYY)([-/.](DD|MM|YYYY)){2}$`) + if !validFormat.MatchString(rawDateFormat) { + return nil, fmt.Errorf("loadConfig: %s must use DD, MM, and YYYY tokens with a single / - or . separator (e.g. DD/MM/YYYY)", DATE_FORMAT_ENV) + } + } + cfg.dateFormat = rawDateFormat cfg.configDir = getenv(CONFIG_DIR_ENV) if cfg.configDir == "" {