Fix index out of range in headline priority parsing

fuzzed - counting is hard...
This commit is contained in:
Niklas Fasching 2019-10-27 15:24:24 +01:00
parent 20970ec872
commit f69b043136
4 changed files with 28 additions and 3 deletions

View file

@ -56,7 +56,7 @@ func (d *Document) parseHeadline(i int, parentStop stopFn) (int, Node) {
} }
} }
if len(text) >= 3 && text[0:2] == "[#" && strings.Contains("ABC", text[2:3]) && text[3] == ']' { if len(text) >= 4 && text[0:2] == "[#" && strings.Contains("ABC", text[2:3]) && text[3] == ']' {
headline.Priority = text[2:3] headline.Priority = text[2:3]
text = strings.TrimSpace(text[4:]) text = strings.TrimSpace(text[4:])
} }

View file

@ -60,7 +60,17 @@
</li> </li>
</ul> </ul>
</li> </li>
<li><a href="#headline-27">Footnotes</a> <li><a href="#headline-27">misc fuzz / regression / edge case</a>
<ul>
<li><a href="#headline-28">index out of range in headline priority parsing</a>
<ul>
<li><a href="#headline-29">[#B</a>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#headline-30">Footnotes</a>
</li> </li>
</ul> </ul>
</nav> </nav>
@ -480,7 +490,16 @@ When inserting an image link like <img src="/home/amos/Pictures/Screenshots/img-
</pre> </pre>
</div> </div>
</div> </div>
<h1 id="headline-27"> <h2 id="headline-27">
misc fuzz / regression / edge case
</h2>
<h3 id="headline-28">
index out of range in headline priority parsing
</h3>
<h4 id="headline-29">
[#B
</h4>
<h1 id="headline-30">
Footnotes Footnotes
</h1> </h1>
<div class="footnotes"> <div class="footnotes">

View file

@ -133,6 +133,9 @@ When inserting an image link like [[/home/amos/Pictures/Screenshots/img-2017-09-
(shrink-window (- (window-height) 12)) (shrink-window (- (window-height) 12))
(ansi-term)) (ansi-term))
#+END_SRC #+END_SRC
** misc fuzz / regression / edge case
*** index out of range in headline priority parsing
**** [#B
* Footnotes * Footnotes
[fn:1] a footnote /with/ *markup* [fn:1] a footnote /with/ *markup*

View file

@ -133,6 +133,9 @@ When inserting an image link like [[/home/amos/Pictures/Screenshots/img-2017-09-
(shrink-window (- (window-height) 12)) (shrink-window (- (window-height) 12))
(ansi-term)) (ansi-term))
#+END_SRC #+END_SRC
** misc fuzz / regression / edge case
*** index out of range in headline priority parsing
**** [#B
* Footnotes * Footnotes
[fn:1] a footnote /with/ *markup* [fn:1] a footnote /with/ *markup*