From b493a11e5ac0b08cea760ecd35065638a2aca5b1 Mon Sep 17 00:00:00 2001 From: FUFSoB Date: Sat, 27 Jun 2026 10:26:39 +0500 Subject: [PATCH] fix: accept zapret config names with any amount of spaces, fixes #6 --- docs/options.md | 4 ++- modules/proxy-suite/options/zapret.nix | 6 ++++- modules/proxy-suite/zapret.nix | 37 +++++++++++++++++++++++--- nix/checks.nix | 24 +++++++++++++++++ 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/docs/options.md b/docs/options.md index 32a7070..44d9cf0 100644 --- a/docs/options.md +++ b/docs/options.md @@ -5022,7 +5022,9 @@ list of string -zapret strategy preset name passed through to the generated zapret configuration\. +zapret strategy preset name selected from the upstream configs +directory\. Exact filenames are accepted, and names that differ only by +whitespace are treated as aliases\. diff --git a/modules/proxy-suite/options/zapret.nix b/modules/proxy-suite/options/zapret.nix index 7a56f6e..b7daaab 100644 --- a/modules/proxy-suite/options/zapret.nix +++ b/modules/proxy-suite/options/zapret.nix @@ -70,7 +70,11 @@ in configName = mkOption { type = types.str; default = "general(ALT)"; - description = "zapret strategy preset name passed through to the generated zapret configuration."; + description = '' + zapret strategy preset name selected from the upstream configs + directory. Exact filenames are accepted, and names that differ only by + whitespace are treated as aliases. + ''; example = "general(ALT)"; }; diff --git a/modules/proxy-suite/zapret.nix b/modules/proxy-suite/zapret.nix index 27ef39b..423304d 100644 --- a/modules/proxy-suite/zapret.nix +++ b/modules/proxy-suite/zapret.nix @@ -120,10 +120,41 @@ let -e 's|${baseZapretPackage}/opt/zapret|'"$out"'/opt/zapret|g' \ {} \; - if [ -f "$out/opt/zapret/configs/${configName}" ]; then - cp "$out/opt/zapret/configs/${configName}" "$out/opt/zapret/config" + requested_config=${lib.escapeShellArg configName} + configs_dir="$out/opt/zapret/configs" + selected_config="$configs_dir/$requested_config" + + config_name_key() { + printf '%s' "$1" | tr -d '[:space:]' + } + + if [ ! -f "$selected_config" ]; then + requested_key=$(config_name_key "$requested_config") + matched_config="" + + for candidate in "$configs_dir"/*; do + [ -f "$candidate" ] || continue + candidate_name="''${candidate##*/}" + + if [ "$(config_name_key "$candidate_name")" = "$requested_key" ]; then + if [ -n "$matched_config" ]; then + echo "proxy-suite: zapret config '$requested_config' is ambiguous after whitespace normalization" >&2 + echo "proxy-suite: matched '$matched_config' and '$candidate'" >&2 + exit 1 + fi + matched_config="$candidate" + fi + done + + if [ -n "$matched_config" ]; then + selected_config="$matched_config" + fi + fi + + if [ -f "$selected_config" ]; then + cp "$selected_config" "$out/opt/zapret/config" else - echo "proxy-suite: zapret config '${configName}' not found in curated package" >&2 + echo "proxy-suite: zapret config '$requested_config' not found in curated package" >&2 ls -la "$out/opt/zapret/configs" >&2 || true exit 1 fi diff --git a/nix/checks.nix b/nix/checks.nix index d4fa042..245f400 100644 --- a/nix/checks.nix +++ b/nix/checks.nix @@ -1030,6 +1030,28 @@ let zapretSyncRules = mkRoutingRules zapretSyncFixture; zapretSyncBase = mkZapretBase zapretSyncFixture; + zapretSpacedConfigAliasFixture = evalProxySuite [ + baseModule + { + services.proxy-suite.zapret = { + enable = true; + configName = "general(ALT12)"; + }; + } + ]; + zapretSpacedConfigAliasBase = mkZapretBase zapretSpacedConfigAliasFixture; + + zapretUnspacedConfigAliasFixture = evalProxySuite [ + baseModule + { + services.proxy-suite.zapret = { + enable = true; + configName = "general (ALT)"; + }; + } + ]; + zapretUnspacedConfigAliasBase = mkZapretBase zapretUnspacedConfigAliasFixture; + zapretSyncNoExtraListsFixture = evalProxySuite [ baseModule { @@ -3545,6 +3567,8 @@ in ! grep -F -- '--hostlist="${zapretSyncBase}/hostlists/list-twitter.txt"' "${zapretSyncBase}/config" ! grep -F -- '--hostlist="${zapretSyncBase}/hostlists/list-instagram.txt"' "${zapretSyncBase}/config" ! grep -F -- '--hostlist="${zapretSyncBase}/hostlists/list-soundcloud.txt"' "${zapretSyncBase}/config" + test -f "${zapretSpacedConfigAliasBase}/config" + test -f "${zapretUnspacedConfigAliasBase}/config" ! grep -F -- '--hostlist="${zapretSyncNoExtraListsBase}/hostlists/list-twitter.txt"' "${zapretSyncNoExtraListsBase}/config" ! grep -F -- '--hostlist="${zapretSyncNoExtraListsBase}/hostlists/list-instagram.txt"' "${zapretSyncNoExtraListsBase}/config" ! grep -F -- '--hostlist="${zapretSyncNoExtraListsBase}/hostlists/list-soundcloud.txt"' "${zapretSyncNoExtraListsBase}/config"