我知道 HTML 在 Semgrep 中是实验性的,但我希望它能在非常简单的匹配上工作(Bash 也是实验性的,并且 它已经足够好了).
如何匹配具有相同 ID 的任意两个元素?
<!-- this should match since both have same IDs -->
<div id="a"></div>
<div id="a"></div>
<!-- this should match since both have same IDs, even though spacing is different (valid HTML) -->
<div id="b"></div>
<div id = "b"></div>
<!-- this should match since both have same IDs, even though different tags -->
<div id="c"></div>
<span id="c"></div>
<!-- self-closing tags should match too -->
<link id="d" rel="stylesheet" href="styles.css">
<span id="d"></span>
rules:
- id: dupe_id
message: duplicate IDs not allowed
languages:
- html
severity: ERROR
patterns:
- pattern-either:
# Both not self-closing
- pattern: <$TAGA id="$X"></$TAGA><$TAGB id="$X"></$TAGB>
# First self-closing
- pattern: <$TAGA id="$X" /><$TAGB id="$X"></$TAGB>
# Second self-closing
- pattern: <$TAGB id="$X"></$TAGB><$TAGA id="$X" />
# Both self-closing
- pattern: <$TAGB id="$X" /><$TAGA id="$X" />
Attemp 只给出了一场比赛,但预期是 4.