Skip to content

Commit

Permalink
Fix panic on empty TOC
Browse files Browse the repository at this point in the history
  • Loading branch information
tallclair committed Jun 27, 2019
1 parent bfd0b5a commit 4dc3d6f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions mdtoc.go
Expand Up @@ -135,9 +135,9 @@ func run(file string, opts options) (string, error) {
return toc, err
}

realStart := start + len(startTOC) + len("\n")
realStart := start + len(startTOC)
oldTOC := string(raw[realStart:end])
if oldTOC == toc {
if strings.TrimSpace(oldTOC) == strings.TrimSpace(toc) {
// No changes required.
return toc, nil
} else if opts.dryrun {
Expand Down
3 changes: 1 addition & 2 deletions testdata/empty_toc.md
Expand Up @@ -5,7 +5,6 @@ description: we should ignore it

# TOC

<!-- toc -->
<!-- /toc -->
<!-- toc --><!-- /toc -->

# Only Heading

0 comments on commit 4dc3d6f

Please sign in to comment.