Skip to content

Commit 42b355f

Browse files
committed
fix: sanitize package list before inserting into config
- Remove "0:" prefix from package names before injecting into Sing-box and Clash configurations. - Ensures consistent formatting of include/exclude package lists. - Prevents malformed entries in sing_config and clash_config.
1 parent b4a2c00 commit 42b355f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

box/scripts/box.service

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ prepare_singbox() {
232232
"${yq}" '(.inbounds[] | select(.type == "tun") | .include_package) = []' -i --output-format=json "${sing_config}"
233233
"${yq}" '(.inbounds[] | select(.type == "tun") | .exclude_package) = []' -i --output-format=json "${sing_config}"
234234
[[ ${proxy_mode} = "blacklist" || ${proxy_mode} = "black" ]] && mode="exclude" || mode="include"
235-
for package in "${packages_list[@]}"; do
235+
236+
# Clean up the "0:" prefix and insert one by one into the config
237+
for raw in "${packages_list[@]}"; do
238+
package=$(echo "$raw" | cut -d':' -f2)
236239
"${yq}" eval '(.inbounds[] | select(.type == "tun") | .'${mode}'_package) += ["'${package}'"]' -i --output-format=json "${sing_config}"
237240
done
238241

@@ -343,9 +346,12 @@ prepare_clash() {
343346
sed -i "s/exclude-package:.*/exclude-package: []/g" "${clash_config}"
344347
sed -i "s/include-package:.*/include-package: []/g" "${clash_config}"
345348

346-
# Add packages to the configuration if list_package is not empty
347349
if [ -n "${list_package}" ]; then
348-
sed -i "s/${mode}-package:.*/${mode}-package: [\"${list_package//,/\",\"}\"]/g" "${clash_config}"
350+
# Remove the "0:" then combine them into one line of commas
351+
list_package_clean=$(echo "$list_package" | cut -d':' -f2 | paste -sd, -)
352+
353+
# Insert into configuration file
354+
sed -i "s/${mode}-package:.*/${mode}-package: [\"${list_package_clean//,/\",\"}\"]/g" "${clash_config}"
349355
fi
350356

351357
sed -i "/tun:/,/enable:/ { /enable: false/ s/enable: false/enable: true/ }" "${clash_config}"

0 commit comments

Comments
 (0)