mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-14 11:54:53 +03: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:
parent
63dcd59fa5
commit
9735879318
Notes:
sideshowbarker
2024-07-19 01:42:10 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/9735879318c Pull-request: https://github.com/SerenityOS/serenity/pull/3859
@ -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);
|
||||
|
@ -40,6 +40,7 @@ public:
|
||||
: m_text(move(text))
|
||||
, m_level(level)
|
||||
{
|
||||
ASSERT(m_level > 0);
|
||||
}
|
||||
virtual ~Heading() override { }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user