github / github/codeql

CodeQL Ruby parser fails on bare & block forwarding in multi-line method calls

Offen
#20,257 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug question
Vorherrschende Sprache
CodeQL
Sterne
10.1k
Forks
2.1k
Ø Merge
2 T. 15 Std.
Gemergte PRs (30 T.)
141

Beschreibung

# 🖼️ Context

CodeQL's Ruby parser encounters parse errors when using Ruby 3.1+'s anonymous block forwarding syntax (&) in specific contexts, despite this being valid Ruby syntax.

## Reproduction Case

```ruby
module TestCase
def method_with_bare_ampersand(&)
some_method_call(
keyword_arg1: "value1",
keyword_arg2: "value2",
keyword_arg3: "value3",
& # <-- CodeQL parse error occurs here
)
end

# This works fine - single line call
def working_method(&)
simple_call(&)
end

private

def some_method_call(keyword_arg1:, keyword_arg2:, keyword_arg3:, &block)
yield if block_given?
end

def simple_call(&block)
yield if block_given?
end
end
```

### Environment
- Repo: [rubygems/rubygems.org](https://github.com/rubygems/rubygems.org)
- recent [workflow run](https://github.com/rubygems/rubygems.org/actions/runs/17104368086/job/48509269173?pr=5925))
- [offending file](https://github.com/rubygems/rubygems.org/blob/ae3f654e67d74122a692de4e7832fa6657d98a7a/app/controllers/concerns/avo_auditable.rb#L26)
- [offending file](https://github.com/rubygems/rubygems.org/blob/ae3f654e67d74122a692de4e7832fa6657d98a7a/app/controllers/concerns/maintenance_tasks_auditable.rb#L26)
- CodeQL CLI version: 2.15.5
- Ruby version: 3.4.x
- Syntax: Valid Ruby (confirmed with ruby -c)

### 📝 Notes

- The issue only occurs with multi-line method calls where & appears on its own line
- Single-line calls with & work correctly
- Named block parameters (e.g., &block) work in all contexts
- This is valid Ruby 3.1+ anonymous block forwarding syntax

### Impact

This prevents CodeQL security analysis on codebases using modern Ruby block forwarding patterns, forcing developers to use less idiomatic code or exclude files from analysis.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, die CodeQL-Analyse für app/controllers/concerns/avo_auditable.rb und app/controllers/concerns/maintenance_tasks_auditable.rb zu reproduzieren, und vergleiche dann das Ergebnis mit ruby -c und der bereitgestellten Reproduktion. Als abgeschlossen gilt die Aufgabe, wenn der CodeQL-Ruby-Parser die Weiterleitung eines anonymen Blocks in einer mehrzeiligen Aufrufanweisung in einer eigenen Zeile akzeptiert und die Analyse ohne Parse-Fehler fortgesetzt wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
ruby
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.