From 3178366d8620c34ac63d7003ccbf49bd1faa8610 Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Fri, 1 Aug 2025 11:05:32 +1000 Subject: [PATCH] workflows: Add check for common LLM targeted unicode characters (#1974) * workflows: Add check for zero width unicode characters * refactor: exclude .git directory in zero width unicode character check * Include additional zero width unicode character in check * refactor: update zero width unicode check to include format characters --- .github/workflows/misc.yml | 12 ++++++++++++ backtester/eventhandlers/portfolio/portfolio_test.go | 2 +- exchanges/bybit/bybit.go | 6 +++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/misc.yml b/.github/workflows/misc.yml index 1c0160a9..83aa67ed 100644 --- a/.github/workflows/misc.yml +++ b/.github/workflows/misc.yml @@ -51,3 +51,15 @@ jobs: echo "::error::Replace !errors.Is(err, target) with testify equivalents" exit 1 + - name: Check for LLM targeted invisible Unicode + run: | + WHITELIST='' + if [[ -z "$WHITELIST" ]]; then + PATTERN='(?!\x20)[\p{Cf}\p{Z}\p{M}]' + else + PATTERN="(?![\x20$WHITELIST])[\p{Cf}\p{Z}\p{M}]" + fi + grep -r -n -I --color=always --exclude-dir=.git -P "$PATTERN" . || exit 0 + echo "::error::Remove zero-width/format, separator or combining-mark characters" + exit 1 + diff --git a/backtester/eventhandlers/portfolio/portfolio_test.go b/backtester/eventhandlers/portfolio/portfolio_test.go index cf195e99..8f2d30b4 100644 --- a/backtester/eventhandlers/portfolio/portfolio_test.go +++ b/backtester/eventhandlers/portfolio/portfolio_test.go @@ -786,7 +786,7 @@ func TestCalculatePNL(t *testing.T) { t.Fatalf("expected one position, received '%v'", len(pos)) } if len(pos[0].PNLHistory) == 0 { - t.Fatal("expected a pnl entry ( ͡° ͜ʖ ͡°)") + t.Fatal("expected a pnl entry 😎") } if !pos[0].UnrealisedPNL.Equal(decimal.NewFromInt(26700)) { // 20 orders * $1 difference * 1x leverage diff --git a/exchanges/bybit/bybit.go b/exchanges/bybit/bybit.go index 302cd7a8..c72b536c 100644 --- a/exchanges/bybit/bybit.go +++ b/exchanges/bybit/bybit.go @@ -1003,7 +1003,7 @@ func (e *Exchange) AddOrReduceMargin(ctx context.Context, arg *AddOrReduceMargin } // GetExecution retrieves users' execution records, sorted by execTime in descending order. However, for Normal spot, they are sorted by execId in descending order. -// Execution Type possible values: 'Trade', 'AdlTrade' Auto-Deleveraging, 'Funding' Funding fee, 'BustTrade' Liquidation, 'Delivery' USDC futures delivery, 'BlockTrade' +// Execution Type possible values: 'Trade', 'AdlTrade' Auto-Deleveraging, 'Funding' Funding fee, 'BustTrade' Liquidation, 'Delivery' USDC futures delivery, 'BlockTrade' // UTA Spot: 'stopOrderType', "" for normal order, "tpslOrder" for TP/SL order, "Stop" for conditional order, "OcoOrder" for OCO order func (e *Exchange) GetExecution(ctx context.Context, category, symbol, orderID, orderLinkID, baseCoin, executionType, stopOrderType, cursor string, startTime, endTime time.Time, limit int64) (*ExecutionResponse, error) { params, err := fillCategoryAndSymbol(category, symbol, true) @@ -1694,8 +1694,8 @@ func (e *Exchange) GetAllowedDepositCoinInfo(ctx context.Context, coin, chain, c } // SetDepositAccount sets auto transfer account after deposit. The same function as the setting for Deposit on web GUI -// account types: CONTRACT Derivatives Account -// 'SPOT' Spot Account 'INVESTMENT' ByFi Account (The service has been offline) 'OPTION' USDC Account 'UNIFIED' UMA or UTA 'FUND' Funding Account +// account types: CONTRACT Derivatives Account +// 'SPOT' Spot Account 'INVESTMENT' ByFi Account (The service has been offline) 'OPTION' USDC Account 'UNIFIED' UMA or UTA 'FUND' Funding Account func (e *Exchange) SetDepositAccount(ctx context.Context, accountType string) (*StatusResponse, error) { if accountType == "" { return nil, errMissingAccountType