Skip to content

manualpathconcat: plus-equals form of manual path concatenation is never detected #54983

Closed

Description

@github-actions

manualpathconcat: compound-assignment += form of manual "/" path concatenation is never detected

Problem

manualpathconcat (pkg/linters/manualpathconcat/manualpathconcat.go) only matches the specific nested-BinaryExpr shape produced by X + "/" + Y (parsed as (X + "/") + Y, see matchSlashSeparator, lines 86-105). Its node filter is []ast.Node{(*ast.BinaryExpr)(nil)} (line 43) — it never inspects ast.AssignStmt.

The idiomatic compound form path += "/" + suffix (equivalent to path = path + "/" + suffix) is represented in the AST as an AssignStmt{Tok: token.ADD_ASSIGN} whose RHS is just "/" + suffix — a two-operand BinaryExpr where X is the "/" literal itself, not a nested BinaryExpr. matchSlashSeparator requires bin.X to be a *ast.BinaryExpr (line 92), so this RHS can never match, regardless of the compound-assignment context. The implicit path + prefix that += contributes is structurally invisible to the analyzer.

Evidence — real production site

pkg/workflow/checkout_config_parser.go:316:

absPath := "$GITHUB_WORKSPACE"
if !isRoot {
    absPath += "/" + relPath   // manual "/" concat via += — NOT flagged
}

This is exactly the pattern the linter exists to catch (manual "/" concatenation building a path-like string) but it produces zero diagnostics today. A repo-wide check (grep -rn '+= "/"' pkg --include="*.go") confirms this is the only current +=-form hit, but the blind spot is structural, not incidental — any future x += "/" + y anywhere in pkg/ will silently bypass the linter forever.

This is the mirror image of a previously-fixed sibling bug: stringsconcatloop (#49046) originally matched only ADD_ASSIGN and missed the plain x = x + y form. Here manualpathconcat matches only the plain nested-BinaryExpr form and misses ADD_ASSIGN.

Impact

  • False negatives: any +=-based manual path join is invisible, undermining the linter's stated purpose (double-slash bugs, missing Clean()-style normalization, non-portable separators).
  • The gap is silent — no diagnostic, no nolint needed, no test failure — so it will keep missing new occurrences as the codebase grows.
  • manualpathconcat is not currently wired into .github/workflows/cgo.yml's LINTER_FLAGS (not yet CI-enforced), so this is a good moment to close the detection gap before enforcement is turned on, avoiding a second silent blind spot at enforcement time.

Recommendation

Add an *ast.AssignStmt case (or extend the node filter to include it) that:

  1. Matches Tok == token.ADD_ASSIGN with a single Lhs/single Rhs.
  2. Checks whether Rhs[0] is "/" + Y (a BinaryExpr whose X operand is the slash literal) — i.e. reuse isSlashLiteral against bin.X directly instead of requiring bin.X to itself be a BinaryExpr.
  3. Reports using Lhs[0] as the effective "left" path segment, mirroring the message format already used for the BinaryExpr case (filepath.Join(<lhs>, <rhs>)).

Validation checklist

  • New testdata case: absPath += "/" + relPath produces the expected diagnostic.
  • Existing BinaryExpr-chain testdata cases still pass unchanged.
  • pkg/workflow/checkout_config_parser.go:316 now flagged (or fixed + nolint'd if the team decides $GITHUB_WORKSPACE is a shell-expanded template string rather than a real filesystem path and intentionally exempt).
  • Re-run analyzer across pkg/ to confirm no other +=-form manual joins are newly surfaced.

Effort: Small — single-file change to manualpathconcat.go plus one new testdata case.

Generated by 🤖 Sergo - Serena Go Expert · agent · 155.1 AIC · ⌖ 9.88 AIC · ⊞ 6.8K · ◷

  • expires on Aug 29, 2026, 8:09 PM UTC-08:00

Activity

  1. added
    cookie
    on Aug 23, 2026
  2. github-actions commented on Aug 23, 2026

    @github-actions
    ContributorAuthor

    🍪 Issue Monster selected this for Copilot

    I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.

    If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    🍪 Om nom nom by Issue Monster · gpt54 · 3.37 AIC · ⌖ 9.92 AIC · ⊞ 10.2K · ◷

  3. linked a pull request that will close this issueDetect `+= "/"` manual path concatenation #54986on Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

cookiesergo

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions