mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 01:00:05 +00:00
LibJS: Count code-points instead of bytes for syntax highlight
This fixes issue #1847, a crash on view-source for https://chalmers.se
This commit is contained in:
parent
c78c706422
commit
84c881fc66
Notes:
github-actions[bot]
2024-10-31 08:44:09 +00:00
Author: https://github.com/todderod
Commit: 84c881fc66
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2067
Reviewed-by: https://github.com/tcl3 ✅
1 changed files with 7 additions and 7 deletions
|
@ -59,21 +59,21 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
|
||||||
Syntax::TextPosition position { 0, 0 };
|
Syntax::TextPosition position { 0, 0 };
|
||||||
Syntax::TextPosition start { 0, 0 };
|
Syntax::TextPosition start { 0, 0 };
|
||||||
|
|
||||||
auto advance_position = [&position](char ch) {
|
auto advance_position = [&position](u32 code_point) {
|
||||||
if (ch == '\n') {
|
if (code_point == '\n') {
|
||||||
position.set_line(position.line() + 1);
|
position.set_line(position.line() + 1);
|
||||||
position.set_column(0);
|
position.set_column(0);
|
||||||
} else
|
} else
|
||||||
position.set_column(position.column() + 1);
|
position.set_column(position.column() + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto append_token = [&](StringView str, Token const& token, bool is_trivia) {
|
auto append_token = [&](Utf8View str, Token const& token, bool is_trivia) {
|
||||||
if (str.is_empty())
|
if (str.is_empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
start = position;
|
start = position;
|
||||||
for (size_t i = 0; i < str.length(); ++i)
|
for (auto code_point : str)
|
||||||
advance_position(str[i]);
|
advance_position(code_point);
|
||||||
|
|
||||||
Syntax::TextDocumentSpan span;
|
Syntax::TextDocumentSpan span;
|
||||||
span.range.set_start(start);
|
span.range.set_start(start);
|
||||||
|
@ -100,10 +100,10 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
|
||||||
|
|
||||||
bool was_eof = false;
|
bool was_eof = false;
|
||||||
for (auto token = lexer.next(); !was_eof; token = lexer.next()) {
|
for (auto token = lexer.next(); !was_eof; token = lexer.next()) {
|
||||||
append_token(token.trivia(), token, true);
|
append_token(Utf8View(token.trivia()), token, true);
|
||||||
|
|
||||||
auto token_start_position = position;
|
auto token_start_position = position;
|
||||||
append_token(token.value(), token, false);
|
append_token(Utf8View(token.value()), token, false);
|
||||||
|
|
||||||
if (token.type() == TokenType::Eof)
|
if (token.type() == TokenType::Eof)
|
||||||
was_eof = true;
|
was_eof = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue