Merge pull request #310 from sasha-spb-ru/fix-strategy-escaping

[blockcheck2] Stop requiring manual escaping in strategy lists
This commit is contained in:
bol-van authored and GitHub committed 2026-09-18 09:51:38 +03:00
commit 3b6f0cc345
4 files changed
+14 -9

No files matched your search

+10 -3
View File
@@ -25,12 +25,19 @@ check_list()
esac
line=$(echo "$line" | tr -d "\r\n")
# dry run eval in subshell. can fail because of unescaped chars or something else
if (eval emptyf $line); then
if (eval emptyf $line) 2>/dev/null; then
# real run in the current shell. can modify vars
eval pktws_curl_test_update "$1" "$2" $line && ok=1
else
echo >&2 BAD STRATEGY: $line
echo >&2 "THIS LINE IS PASSED TO eval SHELL FUNCTION. IT'S INTERPRETED AS A SHELL STATEMENT. SPECIAL CHARS MUST BE ESCAPED"
# $line contains characters that are meaningful to nfqws2/lua-desync
# syntax (e.g. "<" in --out-range=s1<d1, or "(" and "'" in a
# --lua-init=...=tls_mod(...,'rnd') expression) but aren't valid
# shell syntax on their own, so the dry run above rejected it.
# Fall back to a plain (non-eval) split: $line is only word-split
# on whitespace here, nothing in it is re-parsed as shell syntax,
# so these can be used exactly as blockcheck2 itself prints them,
# with no manual escaping needed.
pktws_curl_test_update "$1" "$2" $line && ok=1
fi
done < "$3"
+2 -2
View File
@@ -2,11 +2,11 @@
Скопируйте эту директорию под другим именем в blockcheck2.d, отредактируйте list файлы, впишите туда свои стратегии.
В диалоге blockcheck2.sh выберите тест с названием вашей директории.
Можно комментировать строки символом '#' в начале строки.
Параметры со спец символами типа "<" должны быть эскейпнуты по правилам shell.
Параметры со спец символами типа "<" больше не обязательно эскейпить - если строка не разбирается как shell, она пробуется заново буквально. Эскейпинг по правилам shell по-прежнему работает и пробуется первым.
Альтернативный путь до файлов стратегий можно задать переменными LIST_HTTP, LIST_HTTPS_TLS12, LIST_HTTPS_TLS13, LIST_QUIC.
This is simple strategy tester from a file.
Copy this folder, write your strategies into list files and select your test in blockcheck2 dialog.
Lines can be commented using the '#' symbol at the line start.
Parameters with special symbols like "<" must be escaped.
Parameters with special symbols like "<" no longer need escaping - a line that doesn't parse as shell is retried literally instead of failing. Escaping by shell rules still works too and is tried first.
Strategy list files paths can be overriden in env variables : LIST_HTTP, LIST_HTTPS_TLS12, LIST_HTTPS_TLS13, LIST_QUIC.
+1 -2
View File
@@ -4953,8 +4953,7 @@ NOTEST_QUIC=1 - disable 90-quic.sh tests
A simple tester that uses strategy lists from files. Strategies must be on separate lines; line breaks within a single strategy are not allowed. Separate lists are used for different protocols: `list_http.txt`, `list_https_tls12.txt`, `list_https_tls13.txt`, and `list_quic.sh`. These files support comments starting with `#`.
When defining parameters, keep in mind that they will be interpreted as shell arguments. Special characters must be escaped according to shell rules.
For example, leaving `<` unquoted across the entire parameter or incorrectly quoting the `--luaexec=code=print("abc")` parameter will result in an error. If your Lua code uses strings, it is best to enclose them in single quotes and wrap the entire parameter in double quotes.
When defining parameters, keep in mind that they will first be tried as shell arguments. Special characters (`<`, `(`, `'`, and similar) are shell syntax and would normally need escaping - for example, leaving `<` unquoted across the entire parameter, or incorrectly quoting the `--luaexec=code=print("abc")` parameter, would previously result in an error. If a line fails this way now, it's automatically retried as a plain, unparsed argument list instead (split only on whitespace, nothing re-interpreted), so strategies containing these characters work whether or not you escape them yourself - copy one straight from `blockcheck2`'s own output and it will just work. Escaping by hand (single quotes around Lua strings, the whole parameter wrapped in double quotes) is still supported and still takes priority when it succeeds, for anyone who wants shell-side expansion inside a list line.
Note that `blockcheck2` will output strategy parameters without escaping.
The recommended way to use this is to copy it into its own subdirectory within `blockcheck2.d` and populate the `.txt` files with your tests. Then, select your custom test name from the dialog.
+1 -2
View File
@@ -5141,8 +5141,7 @@ NOTEST_QUIC=1 - отмена тестов 90-quic.sh
Простой тестировщик по списку стратегий из файлов. Стратегии должны быть на отдельных строчках, переносы строки не допускаются. Используются отдельные списки для протоколов - `list_http.txt`, `list_https_tls12.txt`, `list_https_tls13.txt`, `list_quic.sh`. В файлах поддерживаются комментарии, начинающиеся на `#`.
При записи параметров следует учитывать, что они будут интерпретироваться как параметры shell. Специальные символы нужно экранировать по правилам shell.
Если вы оставите "<" без кавычек на всем параметре или возьмете в кавычки параметр `--luaexec=code=print("abc")`, будет ошибка. Если в lua коде используются строки - их стоит заключать в одинарные кавычки, а вокруг параметра - двойные.
При записи параметров следует учитывать, что сначала они будут опробованы как параметры shell. Специальные символы (`<`, `(`, `'` и подобные) являются синтаксисом shell и обычно требуют экранирования - например, раньше "<" без кавычек на всем параметре или неверно взятый в кавычки параметр `--luaexec=code=print("abc")` приводили к ошибке. Теперь, если строка не проходит таким образом, она автоматически пробуется заново как обычный, неразбираемый список аргументов (разбивается только по пробелам, ничего не переинтерпретируется) - поэтому стратегии с такими символами работают вне зависимости от того, экранировали вы их сами или нет, и строку можно скопировать прямо из вывода `blockcheck2` без правок. Ручное экранирование (одинарные кавычки вокруг lua-строк, весь параметр в двойных) по-прежнему поддерживается и имеет приоритет, если срабатывает - для тех, кому нужно shell-раскрытие внутри строки списка.
blockcheck2 будет выдавать параметры стратегий без экранирования.
Самый правильный способ применения - скопировать в свою поддиректорию внутри `blockcheck2.d` и заполнить txt файлы с тестами. Выбрать свое имя теста в диалоге.