treewide: Fix incorrect string escapes

This commit is contained in:
piegames
2024-12-23 21:58:07 +01:00
parent ccd60fa3b5
commit 603733851b
28 changed files with 44 additions and 44 deletions

View File

@@ -475,7 +475,7 @@ rec {
"lib.meta.getExe': The first argument is of type ${typeOf x}, but it should be a derivation instead."; "lib.meta.getExe': The first argument is of type ${typeOf x}, but it should be a derivation instead.";
assert assertMsg (isString y) assert assertMsg (isString y)
"lib.meta.getExe': The second argument is of type ${typeOf y}, but it should be a string instead."; "lib.meta.getExe': The second argument is of type ${typeOf y}, but it should be a string instead.";
assert assertMsg (match ".*\/.*" y == null) assert assertMsg (match ".*/.*" y == null)
"lib.meta.getExe': The second argument \"${y}\" is a nested path with a \"/\" character, but it should just be the name of the executable instead."; "lib.meta.getExe': The second argument \"${y}\" is a nested path with a \"/\" character, but it should just be the name of the executable instead.";
"${getBin x}/bin/${y}"; "${getBin x}/bin/${y}";
} }

View File

@@ -426,7 +426,7 @@ rec {
# If the part is a named placeholder of the form "<...>" don't escape it. # If the part is a named placeholder of the form "<...>" don't escape it.
# It may cause misleading escaping if somebody uses literally "<...>" in their option names. # It may cause misleading escaping if somebody uses literally "<...>" in their option names.
# This is the trade-off to allow for placeholders in option names. # This is the trade-off to allow for placeholders in option names.
isNamedPlaceholder = builtins.match "\<(.*)\>"; isNamedPlaceholder = builtins.match "<(.*)>";
escapeOptionPart = part: escapeOptionPart = part:
if part == "*" || isNamedPlaceholder part != null if part == "*" || isNamedPlaceholder part != null
then part then part

View File

@@ -3,12 +3,12 @@
imports = [ imports = [
{ {
options.sm = lib.mkOption { options.sm = lib.mkOption {
type = lib.types.strMatching "\(.*\)"; type = lib.types.strMatching "\\(.*\\)";
}; };
} }
{ {
options.sm = lib.mkOption { options.sm = lib.mkOption {
type = lib.types.strMatching "\(.*\)"; type = lib.types.strMatching "\\(.*\\)";
}; };
} }
]; ];

View File

@@ -17,7 +17,7 @@ let
offloadCfg = pCfg.offload; offloadCfg = pCfg.offload;
reverseSyncCfg = pCfg.reverseSync; reverseSyncCfg = pCfg.reverseSync;
primeEnabled = syncCfg.enable || reverseSyncCfg.enable || offloadCfg.enable; primeEnabled = syncCfg.enable || reverseSyncCfg.enable || offloadCfg.enable;
busIDType = lib.types.strMatching "([[:print:]]+[\:\@][0-9]{1,3}\:[0-9]{1,2}\:[0-9])?"; busIDType = lib.types.strMatching "([[:print:]]+[:@][0-9]{1,3}:[0-9]{1,2}:[0-9])?";
ibtSupport = useOpenModules || (nvidia_x11.ibtSupport or false); ibtSupport = useOpenModules || (nvidia_x11.ibtSupport or false);
settingsFormat = pkgs.formats.keyValue { }; settingsFormat = pkgs.formats.keyValue { };
in in

View File

@@ -24,7 +24,7 @@ let
; ;
needsEscaping = s: null != builtins.match "[a-zA-Z0-9]+" s; needsEscaping = s: null != builtins.match "[a-zA-Z0-9]+" s;
escapeIfNecessary = s: if needsEscaping s then s else ''"${lib.escape [ "\$" "\"" "\\" "\`" ] s}"''; escapeIfNecessary = s: if needsEscaping s then s else ''"${lib.escape [ "$" "\"" "\\" "`" ] s}"'';
attrsToText = attrsToText =
attrs: attrs:
concatStringsSep "\n" (mapAttrsToList (n: v: ''${n}=${escapeIfNecessary (toString v)}'') attrs) concatStringsSep "\n" (mapAttrsToList (n: v: ''${n}=${escapeIfNecessary (toString v)}'') attrs)

View File

@@ -93,7 +93,7 @@ let
# The idea is to match everything that looks like `$term =` # The idea is to match everything that looks like `$term =`
# but not `# $term something something` # but not `# $term something something`
# or `# $term = some value` because those are comments. # or `# $term = some value` because those are comments.
configContainsSetting = lines: term: (match "^[^#]*\b${term}\b.*=" lines) != null; configContainsSetting = lines: term: (match "[[:blank:]]*${term}[[:blank:]]*=.*" lines) != null;
warnAboutExtraConfigCollisions = map mkExtraConfigCollisionWarning ( warnAboutExtraConfigCollisions = map mkExtraConfigCollisionWarning (
filter (configContainsSetting cfg.extraConfig) automaticallySetPluginSettings filter (configContainsSetting cfg.extraConfig) automaticallySetPluginSettings

View File

@@ -36,7 +36,7 @@ let
}; };
intOrNumberOrRange = lib.types.either lib.types.ints.unsigned ( intOrNumberOrRange = lib.types.either lib.types.ints.unsigned (
lib.types.strMatching "[[:digit:]]+(\-[[:digit:]]+)?" lib.types.strMatching "[[:digit:]]+(-[[:digit:]]+)?"
// { // {
description = "string containing either a number or a range"; description = "string containing either a number or a range";
descriptionClass = "conjunction"; descriptionClass = "conjunction";

View File

@@ -13,7 +13,7 @@ let
name = "goDuration"; name = "goDuration";
description = "Go duration (https://golang.org/pkg/time/#ParseDuration)"; description = "Go duration (https://golang.org/pkg/time/#ParseDuration)";
check = check =
x: types.str.check x && builtins.match "(-?[0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+" x != null; x: types.str.check x && builtins.match "(-?[0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+" x != null;
inherit (types.str) merge; inherit (types.str) merge;
}; };
in in

View File

@@ -105,19 +105,19 @@ in
}; };
# Serve json files with content type header application/json # Serve json files with content type header application/json
"~ \.json$" = { "~ \\.json$" = {
extraConfig = '' extraConfig = ''
add_header Content-Type application/json; add_header Content-Type application/json;
''; '';
}; };
"~ \.tar.xz$" = { "~ \\.tar.xz$" = {
extraConfig = '' extraConfig = ''
add_header Content-Type application/octet-stream; add_header Content-Type application/octet-stream;
''; '';
}; };
"~ \.tar.gz$" = { "~ \\.tar.gz$" = {
extraConfig = '' extraConfig = ''
add_header Content-Type application/octet-stream; add_header Content-Type application/octet-stream;
''; '';

View File

@@ -123,7 +123,7 @@ in
service = lib.mkOption { service = lib.mkOption {
type = nullOr str; type = nullOr str;
default = null; default = null;
description = "The service on which to perform \<action\> after fetching."; description = "The service on which to perform \\<action\\> after fetching.";
}; };
action = lib.mkOption { action = lib.mkOption {

View File

@@ -403,7 +403,7 @@ in
} }
''; '';
}; };
"~* /api/.*\.(jpg|jpeg|png|webp|gif)$" = { "~* /api/.*\\.(jpg|jpeg|png|webp|gif)$" = {
proxyPass = "http://frigate-api"; proxyPass = "http://frigate-api";
recommendedProxySettings = true; recommendedProxySettings = true;
extraConfig = nginxAuthRequest + nginxProxySettings + '' extraConfig = nginxAuthRequest + nginxProxySettings + ''

View File

@@ -367,10 +367,10 @@ in
index = "index.php"; index = "index.php";
tryFiles = "$uri $uri/ /index.php?$query_string"; tryFiles = "$uri $uri/ /index.php?$query_string";
}; };
"~ \.php$".extraConfig = '' "~ \\.php$".extraConfig = ''
fastcgi_pass unix:${config.services.phpfpm.pools."agorakit".socket}; fastcgi_pass unix:${config.services.phpfpm.pools."agorakit".socket};
''; '';
"~ \.(js|css|gif|png|ico|jpg|jpeg)$" = { "~ \\.(js|css|gif|png|ico|jpg|jpeg)$" = {
extraConfig = "expires 365d;"; extraConfig = "expires 365d;";
}; };
}; };

View File

@@ -328,7 +328,7 @@ in
''; '';
}; };
locations."~ \.php$" = { locations."~ \\.php$" = {
fastcgiParams = { fastcgiParams = {
SERVER_NAME = "$host"; SERVER_NAME = "$host";
}; };

View File

@@ -496,7 +496,7 @@ in
return 302 https://$host/dav/; return 302 https://$host/dav/;
''; '';
}; };
"~ ^(.+\.php)(.*)$" = { "~ ^(.+\\.php)(.*)$" = {
extraConfig = '' extraConfig = ''
try_files $fastcgi_script_name =404; try_files $fastcgi_script_name =404;
include ${config.services.nginx.package}/conf/fastcgi_params; include ${config.services.nginx.package}/conf/fastcgi_params;

View File

@@ -925,7 +925,7 @@ in
}; };
"~ ^/uploads/short-url/" = proxy { }; "~ ^/uploads/short-url/" = proxy { };
"~ ^/secure-media-uploads/" = proxy { }; "~ ^/secure-media-uploads/" = proxy { };
"~* (fonts|assets|plugins|uploads)/.*\.(eot|ttf|woff|woff2|ico|otf)$".extraConfig = "~* (fonts|assets|plugins|uploads)/.*\\.(eot|ttf|woff|woff2|ico|otf)$".extraConfig =
cache_1y cache_1y
+ '' + ''
add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Origin *;

View File

@@ -436,7 +436,7 @@ in
extraConfig = "internal;"; extraConfig = "internal;";
}; };
"~ ^/lib.*\.(js|css|gif|png|ico|jpg|jpeg)$" = { "~ ^/lib.*\\.(js|css|gif|png|ico|jpg|jpeg)$" = {
extraConfig = "expires 365d;"; extraConfig = "expires 365d;";
}; };

View File

@@ -239,7 +239,7 @@ in
sendfile off; sendfile off;
''; '';
}; };
"~ \.php$" = { "~ \\.php$" = {
extraConfig = '' extraConfig = ''
include ${config.services.nginx.package}/conf/fastcgi_params ; include ${config.services.nginx.package}/conf/fastcgi_params ;
fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_param SCRIPT_FILENAME $request_filename;

View File

@@ -361,7 +361,7 @@ in
sendfile off; sendfile off;
''; '';
}; };
"~ \.php$" = { "~ \\.php$" = {
extraConfig = '' extraConfig = ''
include ${config.services.nginx.package}/conf/fastcgi_params ; include ${config.services.nginx.package}/conf/fastcgi_params ;
fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_param SCRIPT_FILENAME $request_filename;

View File

@@ -164,7 +164,7 @@ in
enable = true; enable = true;
virtualHosts."${cfg.domain}" = { virtualHosts."${cfg.domain}" = {
root = "${cfg.stateDir}/public"; root = "${cfg.stateDir}/public";
locations."~ \.php$".extraConfig = '' locations."~ \\.php$".extraConfig = ''
fastcgi_pass unix:${config.services.phpfpm.pools.flarum.socket}; fastcgi_pass unix:${config.services.phpfpm.pools.flarum.socket};
fastcgi_index site.php; fastcgi_index site.php;
''; '';

View File

@@ -211,7 +211,7 @@ in
# php files handling # php files handling
# this regex is mandatory because of the API # this regex is mandatory because of the API
locations."~ ^.+?\.php(/.*)?$".extraConfig = '' locations."~ ^.+?\\.php(/.*)?$".extraConfig = ''
fastcgi_pass unix:${config.services.phpfpm.pools.${cfg.pool}.socket}; fastcgi_pass unix:${config.services.phpfpm.pools.${cfg.pool}.socket};
fastcgi_split_path_info ^(.+\.php)(/.*)$; fastcgi_split_path_info ^(.+\.php)(/.*)$;
# By default, the variable PATH_INFO is not set under PHP-FPM # By default, the variable PATH_INFO is not set under PHP-FPM

View File

@@ -355,10 +355,10 @@ in {
index = "index.php"; index = "index.php";
tryFiles = "$uri $uri/ /index.php?$query_string"; tryFiles = "$uri $uri/ /index.php?$query_string";
}; };
"~ \.php$".extraConfig = '' "~ \\.php$".extraConfig = ''
fastcgi_pass unix:${config.services.phpfpm.pools."monica".socket}; fastcgi_pass unix:${config.services.phpfpm.pools."monica".socket};
''; '';
"~ \.(js|css|gif|png|ico|jpg|jpeg)$" = { "~ \\.(js|css|gif|png|ico|jpg|jpeg)$" = {
extraConfig = "expires 365d;"; extraConfig = "expires 365d;";
}; };
}; };

View File

@@ -105,27 +105,27 @@ in
virtualHosts.${cfg.hostname} = { virtualHosts.${cfg.hostname} = {
locations = { locations = {
# /etc/nginx/includes/ds-docservice.conf # /etc/nginx/includes/ds-docservice.conf
"~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(web-apps\/apps\/api\/documents\/api\.js)$".extraConfig = "~ ^(\\/[\\d]+\\.[\\d]+\\.[\\d]+[\\.|-][\\d]+)?\\/(web-apps\\/apps\\/api\\/documents\\/api\\.js)$".extraConfig =
'' ''
expires -1; expires -1;
alias ${cfg.package}/var/www/onlyoffice/documentserver/$2; alias ${cfg.package}/var/www/onlyoffice/documentserver/$2;
''; '';
"~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(web-apps)(\/.*\.json)$".extraConfig = '' "~ ^(\\/[\\d]+\\.[\\d]+\\.[\\d]+[\\.|-][\\d]+)?\\/(web-apps)(\\/.*\\.json)$".extraConfig = ''
expires 365d; expires 365d;
error_log /dev/null crit; error_log /dev/null crit;
alias ${cfg.package}/var/www/onlyoffice/documentserver/$2$3; alias ${cfg.package}/var/www/onlyoffice/documentserver/$2$3;
''; '';
"~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(sdkjs-plugins)(\/.*\.json)$".extraConfig = '' "~ ^(\\/[\\d]+\\.[\\d]+\\.[\\d]+[\\.|-][\\d]+)?\\/(sdkjs-plugins)(\\/.*\\.json)$".extraConfig = ''
expires 365d; expires 365d;
error_log /dev/null crit; error_log /dev/null crit;
alias ${cfg.package}/var/www/onlyoffice/documentserver/$2$3; alias ${cfg.package}/var/www/onlyoffice/documentserver/$2$3;
''; '';
"~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(web-apps|sdkjs|sdkjs-plugins|fonts)(\/.*)$".extraConfig = "~ ^(\\/[\\d]+\\.[\\d]+\\.[\\d]+[\\.|-][\\d]+)?\\/(web-apps|sdkjs|sdkjs-plugins|fonts)(\\/.*)$".extraConfig =
'' ''
expires 365d; expires 365d;
alias ${cfg.package}/var/www/onlyoffice/documentserver/$2$3; alias ${cfg.package}/var/www/onlyoffice/documentserver/$2$3;
''; '';
"~* ^(\/cache\/files.*)(\/.*)".extraConfig = '' "~* ^(\\/cache\\/files.*)(\\/.*)".extraConfig = ''
alias /var/lib/onlyoffice/documentserver/App_Data$1; alias /var/lib/onlyoffice/documentserver/App_Data$1;
add_header Content-Disposition "attachment; filename*=UTF-8''$arg_filename"; add_header Content-Disposition "attachment; filename*=UTF-8''$arg_filename";
@@ -141,12 +141,12 @@ in
return 410; return 410;
} }
''; '';
"~* ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(internal)(\/.*)$".extraConfig = '' "~* ^(\\/[\\d]+\\.[\\d]+\\.[\\d]+[\\.|-][\\d]+)?\\/(internal)(\\/.*)$".extraConfig = ''
allow 127.0.0.1; allow 127.0.0.1;
deny all; deny all;
proxy_pass http://onlyoffice-docservice/$2$3; proxy_pass http://onlyoffice-docservice/$2$3;
''; '';
"~* ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(info)(\/.*)$".extraConfig = '' "~* ^(\\/[\\d]+\\.[\\d]+\\.[\\d]+[\\.|-][\\d]+)?\\/(info)(\\/.*)$".extraConfig = ''
allow 127.0.0.1; allow 127.0.0.1;
deny all; deny all;
proxy_pass http://onlyoffice-docservice/$2$3; proxy_pass http://onlyoffice-docservice/$2$3;
@@ -154,19 +154,19 @@ in
"/".extraConfig = '' "/".extraConfig = ''
proxy_pass http://onlyoffice-docservice; proxy_pass http://onlyoffice-docservice;
''; '';
"~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?(\/doc\/.*)".extraConfig = '' "~ ^(\\/[\\d]+\\.[\\d]+\\.[\\d]+[\\.|-][\\d]+)?(\\/doc\\/.*)".extraConfig = ''
proxy_pass http://onlyoffice-docservice$2; proxy_pass http://onlyoffice-docservice$2;
proxy_http_version 1.1; proxy_http_version 1.1;
''; '';
"/${cfg.package.version}/".extraConfig = '' "/${cfg.package.version}/".extraConfig = ''
proxy_pass http://onlyoffice-docservice/; proxy_pass http://onlyoffice-docservice/;
''; '';
"~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(dictionaries)(\/.*)$".extraConfig = '' "~ ^(\\/[\\d]+\\.[\\d]+\\.[\\d]+[\\.|-][\\d]+)?\\/(dictionaries)(\\/.*)$".extraConfig = ''
expires 365d; expires 365d;
alias ${cfg.package}/var/www/onlyoffice/documentserver/$2$3; alias ${cfg.package}/var/www/onlyoffice/documentserver/$2$3;
''; '';
# /etc/nginx/includes/ds-example.conf # /etc/nginx/includes/ds-example.conf
"~ ^(\/welcome\/.*)$".extraConfig = '' "~ ^(\\/welcome\\/.*)$".extraConfig = ''
expires 365d; expires 365d;
alias ${cfg.package}/var/www/onlyoffice/documentserver-example$1; alias ${cfg.package}/var/www/onlyoffice/documentserver-example$1;
index docker.html; index docker.html;

View File

@@ -696,7 +696,7 @@ in
}; };
# Bypass PeerTube for performance reasons. # Bypass PeerTube for performance reasons.
locations."~ ^/client/(assets/images/(icons/icon-36x36\.png|icons/icon-48x48\.png|icons/icon-72x72\.png|icons/icon-96x96\.png|icons/icon-144x144\.png|icons/icon-192x192\.png|icons/icon-512x512\.png|logo\.svg|favicon\.png|default-playlist\.jpg|default-avatar-account\.png|default-avatar-account-48x48\.png|default-avatar-video-channel\.png|default-avatar-video-channel-48x48\.png))$" = locations."~ ^/client/(assets/images/(icons/icon-36x36\\.png|icons/icon-48x48\\.png|icons/icon-72x72\\.png|icons/icon-96x96\\.png|icons/icon-144x144\\.png|icons/icon-192x192\\.png|icons/icon-512x512\\.png|logo\\.svg|favicon\\.png|default-playlist\\.jpg|default-avatar-account\\.png|default-avatar-account-48x48\\.png|default-avatar-video-channel\\.png|default-avatar-video-channel-48x48\\.png))$" =
{ {
tryFiles = "/client-overrides/$1 /client/$1 $1"; tryFiles = "/client-overrides/$1 /client/$1 $1";
priority = 1310; priority = 1310;
@@ -704,7 +704,7 @@ in
extraConfig = nginxCommonHeaders; extraConfig = nginxCommonHeaders;
}; };
locations."~ ^/client/(.*\.(js|css|png|svg|woff2|otf|ttf|woff|eot))$" = { locations."~ ^/client/(.*\\.(js|css|png|svg|woff2|otf|ttf|woff|eot))$" = {
alias = "${cfg.package}/client/dist/$1"; alias = "${cfg.package}/client/dist/$1";
priority = 1320; priority = 1320;
extraConfig = extraConfig =

View File

@@ -186,7 +186,7 @@ in
sendfile off; sendfile off;
''; '';
}; };
"~ \.php$" = { "~ \\.php$" = {
extraConfig = '' extraConfig = ''
include ${config.services.nginx.package}/conf/fastcgi_params ; include ${config.services.nginx.package}/conf/fastcgi_params ;
fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_param SCRIPT_FILENAME $request_filename;

View File

@@ -305,7 +305,7 @@ in
${cfg.hostName} = { ${cfg.hostName} = {
root = cfg.dataDir; root = cfg.dataDir;
locations = { locations = {
"~ [^/]\.php(/|$)" = { "~ [^/]\\.php(/|$)" = {
extraConfig = '' extraConfig = ''
fastcgi_split_path_info ^(.+?\.php)(/.*)$; fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) { if (!-f $document_root$fastcgi_script_name) {

View File

@@ -368,7 +368,7 @@ in {
index = "index.php"; index = "index.php";
extraConfig = ''try_files $uri $uri/ /index.php?$query_string;''; extraConfig = ''try_files $uri $uri/ /index.php?$query_string;'';
}; };
"~ \.php$" = { "~ \\.php$" = {
extraConfig = '' extraConfig = ''
try_files $uri $uri/ /index.php?$query_string; try_files $uri $uri/ /index.php?$query_string;
include ${config.services.nginx.package}/conf/fastcgi_params; include ${config.services.nginx.package}/conf/fastcgi_params;
@@ -378,7 +378,7 @@ in {
${optionalString (cfg.nginx.addSSL || cfg.nginx.forceSSL || cfg.nginx.onlySSL || cfg.nginx.enableACME) "fastcgi_param HTTPS on;"} ${optionalString (cfg.nginx.addSSL || cfg.nginx.forceSSL || cfg.nginx.onlySSL || cfg.nginx.enableACME) "fastcgi_param HTTPS on;"}
''; '';
}; };
"~ \.(js|css|gif|png|ico|jpg|jpeg)$" = { "~ \\.(js|css|gif|png|ico|jpg|jpeg)$" = {
extraConfig = "expires 365d;"; extraConfig = "expires 365d;";
}; };
}; };

View File

@@ -342,7 +342,7 @@ in
index = "index.html index.htm index.php"; index = "index.html index.htm index.php";
tryFiles = "$uri $uri/ =404"; tryFiles = "$uri $uri/ =404";
}; };
locations."~ \.php$".extraConfig = '' locations."~ \\.php$".extraConfig = ''
fastcgi_pass unix:${fpm.socket}; fastcgi_pass unix:${fpm.socket};
fastcgi_index index.php; fastcgi_index index.php;
''; '';

View File

@@ -155,7 +155,7 @@ in
}; };
background = mkOption { background = mkOption {
type = types.either types.path (types.strMatching "^#[0-9]\{6\}$"); type = types.either types.path (types.strMatching "^#[0-9]{6}$");
# Manual cannot depend on packages, we are actually setting the default in config below. # Manual cannot depend on packages, we are actually setting the default in config below.
defaultText = literalExpression "pkgs.nixos-artwork.wallpapers.simple-dark-gray-bottom.gnomeFilePath"; defaultText = literalExpression "pkgs.nixos-artwork.wallpapers.simple-dark-gray-bottom.gnomeFilePath";
description = '' description = ''