Skip to content

Commit 039d89a

Browse files
sibprogrammerbukzor
andcommitted
Anchor IsJSON regex to prevent false positives on CDATA
Co-Authored-By: Buck Evan <workitharder@gmail.com>
1 parent afb6dbc commit 039d89a

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

internal/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ func IsHTML(input string) bool {
531531

532532
func IsJSON(input string) bool {
533533
input = strings.ToLower(input)
534-
matched, _ := regexp.MatchString(`\s*[{\[]`, input)
534+
matched, _ := regexp.MatchString(`^\s*[{\[]`, input)
535535
return matched
536536
}
537537

internal/utils/utils_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ func TestIsJSON(t *testing.T) {
184184
assert.True(t, IsJSON(`[1, 2, 3]`))
185185
assert.True(t, IsJSON(` {}`))
186186
assert.False(t, IsJSON(`<html></html>`))
187+
assert.False(t, IsJSON(`<![CDATA[text]]>`))
187188
}
188189

189190
func TestPagerPrint(t *testing.T) {

0 commit comments

Comments
 (0)