go-wiki icon indicating copy to clipboard operation
go-wiki copied to clipboard

Fetching last section from a page panics

Open ralscha opened this issue 1 year ago • 0 comments

There is a bug when fetching the last section from a page. The following program panics with this error panic: runtime error: slice bounds out of range [124683:124682]

package main

import (
	"fmt"
	gowiki "github.com/trietmn/go-wiki"
	"log"
)

func main() {
	page, err := gowiki.GetPage("Rafael Nadal", -1, false, true)
	if err != nil {
		log.Fatal(err)
	}

	pageSection, err := page.GetSection("External links")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("External links: ", pageSection)
}

Problem is in page.go line 405 and 406. end is never -1.

end := start + strings.Index(content[start:], "==")
if end == -1 {
	page.SectionOffset[section] = []int{start, len(content)}
	return content[start:], nil
}

ralscha avatar Oct 19 '24 12:10 ralscha