fix: accept zapret config names with any amount of spaces, fixes #6
This commit is contained in:
4 files changed
+66
-5
No files matched your search
+3
-1
@@ -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\.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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)";
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user