Skip to content

Commit feddecd

Browse files
trflynn89awesomekling
authored andcommitted
LibWeb: Emit the current token before EOF on invalid comments
The spec for each of these state: -> EOF: This is an eof-in-comment parse error. Emit the current comment token. Emit an end-of-file token. We were neglecting to emit the current comment token before emitting an EOF token. Note the existing EMIT_CURRENT_TOKEN macro was unused.
1 parent 775282f commit feddecd

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,17 @@ namespace Web::HTML {
137137
return m_queued_tokens.dequeue(); \
138138
} while (0)
139139

140-
#define EMIT_CURRENT_TOKEN \
140+
#define EMIT_CURRENT_TOKEN_FOLLOWED_BY_EOF \
141141
do { \
142142
VERIFY(m_current_builder.is_empty()); \
143143
will_emit(m_current_token); \
144144
m_queued_tokens.enqueue(move(m_current_token)); \
145+
\
146+
m_has_emitted_eof = true; \
147+
create_new_token(HTMLToken::Type::EndOfFile); \
148+
will_emit(m_current_token); \
149+
m_queued_tokens.enqueue(move(m_current_token)); \
150+
\
145151
return m_queued_tokens.dequeue(); \
146152
} while (0)
147153

@@ -1428,7 +1434,7 @@ Optional<HTMLToken> HTMLTokenizer::next_token(StopAtInsertionPoint stop_at_inser
14281434
ON_EOF
14291435
{
14301436
log_parse_error();
1431-
EMIT_EOF;
1437+
EMIT_CURRENT_TOKEN_FOLLOWED_BY_EOF;
14321438
}
14331439
ANYTHING_ELSE
14341440
{
@@ -1460,7 +1466,7 @@ Optional<HTMLToken> HTMLTokenizer::next_token(StopAtInsertionPoint stop_at_inser
14601466
{
14611467
log_parse_error();
14621468
m_current_token.set_comment(consume_current_builder());
1463-
EMIT_EOF;
1469+
EMIT_CURRENT_TOKEN_FOLLOWED_BY_EOF;
14641470
}
14651471
ANYTHING_ELSE
14661472
{
@@ -1491,7 +1497,7 @@ Optional<HTMLToken> HTMLTokenizer::next_token(StopAtInsertionPoint stop_at_inser
14911497
{
14921498
log_parse_error();
14931499
m_current_token.set_comment(consume_current_builder());
1494-
EMIT_EOF;
1500+
EMIT_CURRENT_TOKEN_FOLLOWED_BY_EOF;
14951501
}
14961502
ANYTHING_ELSE
14971503
{
@@ -1519,7 +1525,7 @@ Optional<HTMLToken> HTMLTokenizer::next_token(StopAtInsertionPoint stop_at_inser
15191525
{
15201526
log_parse_error();
15211527
m_current_token.set_comment(consume_current_builder());
1522-
EMIT_EOF;
1528+
EMIT_CURRENT_TOKEN_FOLLOWED_BY_EOF;
15231529
}
15241530
ANYTHING_ELSE
15251531
{
@@ -1540,7 +1546,7 @@ Optional<HTMLToken> HTMLTokenizer::next_token(StopAtInsertionPoint stop_at_inser
15401546
{
15411547
log_parse_error();
15421548
m_current_token.set_comment(consume_current_builder());
1543-
EMIT_EOF;
1549+
EMIT_CURRENT_TOKEN_FOLLOWED_BY_EOF;
15441550
}
15451551
ANYTHING_ELSE
15461552
{

0 commit comments

Comments
 (0)