1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

LibMarkdown: Don't parse lines starting with a space as heading

This fixes a bug where lines starting with a space would get parsed as
"level 0" headings - it would not find a "#" and therefore never
increase the level counter (starting at zero), which then would cause
the check for "space after #" pass (again, there is no "#").

Eventually we would get funny results like this:

    <h0>[n-1 spaces]oops!</h0>

Also ASSERT(level > 0) in the Heading constructor.
This commit is contained in:
Linus Groh 2020-10-26 17:44:43 +00:00 committed by Andreas Kling
parent 63dcd59fa5
commit 9735879318
2 changed files with 4 additions and 2 deletions

View file

@ -67,11 +67,12 @@ OwnPtr<Heading> Heading::parse(Vector<StringView>::ConstIterator& lines)
const StringView& line = *lines;
size_t level;
for (level = 0; level < line.length(); level++)
for (level = 0; level < line.length(); level++) {
if (line[level] != '#')
break;
}
if (level >= line.length() || line[level] != ' ')
if (!level || level >= line.length() || line[level] != ' ')
return nullptr;
StringView title_view = line.substring_view(level + 1, line.length() - level - 1);