Handle malformed :PROPERTY: drawers

Until now we'd get index out of range errors trying to index into the match if
:PROPERTIES: was followed by a non-property. Thanks fuzz
This commit is contained in:
Niklas Fasching 2019-09-28 15:08:53 +02:00
parent 76b157b8ce
commit adeeb9235d
5 changed files with 28 additions and 0 deletions

View file

@ -67,6 +67,9 @@ func (d *Document) parsePropertyDrawer(i int, parentStop stopFn) (int, Node) {
} }
for ; !stop(d, i); i++ { for ; !stop(d, i); i++ {
m := propertyRegexp.FindStringSubmatch(d.tokens[i].matches[0]) m := propertyRegexp.FindStringSubmatch(d.tokens[i].matches[0])
if m == nil {
return 0, nil
}
k, v := strings.ToUpper(m[2]), strings.TrimSpace(m[4]) k, v := strings.ToUpper(m[2]), strings.TrimSpace(m[4])
drawer.Properties = append(drawer.Properties, []string{k, v}) drawer.Properties = append(drawer.Properties, []string{k, v})
} }

View file

@ -12,6 +12,8 @@
</li> </li>
<li><a href="#headline-6">excluded headline</a> <li><a href="#headline-6">excluded headline</a>
</li> </li>
<li><a href="#headline-7">malformed property drawer</a>
</li>
</ul> </ul>
</nav> </nav>
<h1 id="headline-1"> <h1 id="headline-1">
@ -76,3 +78,13 @@ it&#39;s possible to use <code class="verbatim">#+SETUPFILE</code> - in this cas
</pre> </pre>
</div> </div>
</div> </div>
<h1 id="headline-7">
malformed property drawer
</h1>
<p>
:PROPERTIES:
not a property
</p>
<p>
:END:
</p>

View file

@ -27,3 +27,7 @@ it's possible to use =#+SETUPFILE= - in this case the setup file contains the fo
this headline and it's content are not exported as it is marked with an =EXCLUDE_TAGS= tag. this headline and it's content are not exported as it is marked with an =EXCLUDE_TAGS= tag.
By default =EXCLUDE_TAGS= is just =:noexport:=. By default =EXCLUDE_TAGS= is just =:noexport:=.
* malformed property drawer
:PROPERTIES:
not a property
:END:

View file

@ -27,3 +27,7 @@ it's possible to use =#+SETUPFILE= - in this case the setup file contains the fo
this headline and it's content are not exported as it is marked with an =EXCLUDE_TAGS= tag. this headline and it's content are not exported as it is marked with an =EXCLUDE_TAGS= tag.
By default =EXCLUDE_TAGS= is just =:noexport:=. By default =EXCLUDE_TAGS= is just =:noexport:=.
* malformed property drawer
:PROPERTIES:
not a property
:END:

View file

@ -145,6 +145,11 @@ it&#39;s possible to use =#+SETUPFILE= - in this case the setup file contains th
* excluded headline :custom_noexport: * excluded headline :custom_noexport:
this headline and it&#39;s content are not exported as it is marked with an =EXCLUDE_TAGS= tag. this headline and it&#39;s content are not exported as it is marked with an =EXCLUDE_TAGS= tag.
By default =EXCLUDE_TAGS= is just =:noexport:=. By default =EXCLUDE_TAGS= is just =:noexport:=.
* malformed property drawer
:PROPERTIES:
not a property
:END:
</pre> </pre>
</div> </div>
</div> </div>