github / github/codeql

Ruby: ERB parse failure with trailing implicit keyword argument

オープン
#16,006 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
acknowledged bug Ruby
主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 15時間
マージ済み PR(30日)
141

説明

The following example causes a syntax error, but it shouldn't. I think it is due to the way CodeQL interprets ERB. Instead of inserting newlines it may be better for CodeQL to insert explicit semicolons in most cases. There is not really a right way to interpret ERB, because ERB has no specification and there are many ERB interpreters each with their own flavours. We should probably emulate the most often used Rails flavour as closely as possible.

```
<% def foo bar:; end %>
<% bar = 1 %>
<%= foo bar: %>
<% print "hello" %>
```
What's happening is roughly, that the above gets parsed as follows (this is also invalid according to the real Ruby interpreter)
```
def foo bar:; end
bar = 1
foo bar:
print "hello"
```
instead of as (note the extra `;`)
```
def foo bar:; end
bar = 1
foo bar: ;
print "hello"
```

The ERB interpreter of Rails usually inserts `;` symbols between tags, but sometimes it inserts a newline (to make using blocks easier). CodeQL instead always inserts a newline. This difference is hardly ever a problem because Ruby treats newlines as implicit `;` symbols in almost all cases. The trouble is the "almost", there are a few corner cases, and newlines after a keyword argument are one of them.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。