Skip to content

Commit

Permalink
Fix crash if tags/marks contains invalid entry (gokcehan#1614)
Browse files Browse the repository at this point in the history
* Fix crash if tags file contains invalid entry

* Fix crash if marks file contains invalid entry
  • Loading branch information
joelim-work authored Mar 3, 2024
1 parent 8ee8592 commit 055ce47
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -1868,9 +1868,12 @@ func (nav *nav) readMarks() error {

scanner := bufio.NewScanner(f)
for scanner.Scan() {
toks := strings.SplitN(scanner.Text(), ":", 2)
if _, ok := nav.marks[toks[0]]; !ok {
nav.marks[toks[0]] = toks[1]
mark, path, found := strings.Cut(scanner.Text(), ":")
if !found {
return fmt.Errorf("invalid marks file entry: %s", scanner.Text())
}
if _, ok := nav.marks[mark]; !ok {
nav.marks[mark] = path
}
}

Expand Down Expand Up @@ -1923,12 +1926,12 @@ func (nav *nav) readTags() error {

scanner := bufio.NewScanner(f)
for scanner.Scan() {
text := scanner.Text()
ind := strings.LastIndex(text, ":")
path := text[0:ind]
mark := text[ind+1:]
path, tag, found := strings.Cut(scanner.Text(), ":")
if !found {
return fmt.Errorf("invalid tags file entry: %s", scanner.Text())
}
if _, ok := nav.tags[path]; !ok {
nav.tags[path] = mark
nav.tags[path] = tag
}
}

Expand Down

0 comments on commit 055ce47

Please sign in to comment.