Skip to content

Commit a0dc97a

Browse files
vnykmshrkjk
authored andcommitted
fix: check IndexByte return before adding in tagLength
tagLength() adds the return value of bytes.IndexByte directly to the current index. When '>' is not found, IndexByte returns -1, which decrements i instead of making it negative. The guard `if i < 0` never triggers, causing leftAngle() to silently skip characters. Store the IndexByte result in a separate variable and check it before adding to i.
1 parent 554ac1d commit a0dc97a

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

inline_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,14 @@ func TestSkipHTML(t *testing.T) {
12861286
}, TestParams{Flags: html.SkipHTML})
12871287
}
12881288

1289+
func TestTagLengthUnclosedAngle(t *testing.T) {
1290+
// Unclosed angle brackets with short tag names should not lose content
1291+
doTestsParam(t, []string{
1292+
"click <a href content",
1293+
"<p>click &lt;a href content</p>\n",
1294+
}, TestParams{Flags: html.SkipHTML})
1295+
}
1296+
12891297
func TestInlineMath(t *testing.T) {
12901298
doTestsParam(t, []string{
12911299
"$a_b$",

parser/inline.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,10 +1073,11 @@ func tagLength(data []byte) (autolink autolinkType, end int) {
10731073
// one of the forbidden chars has been found
10741074
autolink = notAutolink
10751075
}
1076-
i += bytes.IndexByte(data[i:], '>')
1077-
if i < 0 {
1076+
j = bytes.IndexByte(data[i:], '>')
1077+
if j < 0 {
10781078
return autolink, 0
10791079
}
1080+
i += j
10801081
return autolink, i + 1
10811082
}
10821083

0 commit comments

Comments
 (0)