mirror of
https://github.com/miniflux/v2.git
synced 2025-08-11 17:51:01 +00:00
fix(parser): handle feeds with leading whitespace that exceeds buffer size
This commit is contained in:
parent
5eab4753e8
commit
54abd0a736
2 changed files with 88 additions and 6 deletions
|
@ -77,3 +77,56 @@ func TestDetectUnknown(t *testing.T) {
|
|||
t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatUnknown)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectJSONWithLargeLeadingWhitespace(t *testing.T) {
|
||||
leadingWhitespace := strings.Repeat(" ", 10000)
|
||||
data := leadingWhitespace + `{
|
||||
"version" : "https://jsonfeed.org/version/1",
|
||||
"title" : "Example with lots of leading whitespace"
|
||||
}`
|
||||
format, _ := DetectFeedFormat(strings.NewReader(data))
|
||||
|
||||
if format != FormatJSON {
|
||||
t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatJSON)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectJSONWithMixedWhitespace(t *testing.T) {
|
||||
leadingWhitespace := strings.Repeat("\n\t ", 10000)
|
||||
data := leadingWhitespace + `{
|
||||
"version" : "https://jsonfeed.org/version/1",
|
||||
"title" : "Example with mixed whitespace"
|
||||
}`
|
||||
format, _ := DetectFeedFormat(strings.NewReader(data))
|
||||
|
||||
if format != FormatJSON {
|
||||
t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatJSON)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectOnlyWhitespace(t *testing.T) {
|
||||
data := strings.Repeat(" \t\n\r", 10000)
|
||||
format, _ := DetectFeedFormat(strings.NewReader(data))
|
||||
|
||||
if format != FormatUnknown {
|
||||
t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatUnknown)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectJSONSmallerThanBuffer(t *testing.T) {
|
||||
data := `{"version":"1"}` // This is only 15 bytes, well below the 32-byte buffer
|
||||
format, _ := DetectFeedFormat(strings.NewReader(data))
|
||||
|
||||
if format != FormatJSON {
|
||||
t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatJSON)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectJSONWithWhitespaceSmallerThanBuffer(t *testing.T) {
|
||||
data := ` {"title":"test"} `
|
||||
format, _ := DetectFeedFormat(strings.NewReader(data))
|
||||
|
||||
if format != FormatJSON {
|
||||
t.Errorf(`Wrong format detected: %q instead of %q`, format, FormatJSON)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue