mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 10:18:15 +09:00
js: Convert non-UTF-8 encoded files to UTF-8 before parsing
This commit is contained in:
parent
9e5abec6f1
commit
b36c3a68d8
Notes:
sideshowbarker
2024-07-17 14:25:47 +09:00
Author: https://github.com/trflynn89
Commit: b36c3a68d8
Pull-request: https://github.com/SerenityOS/serenity/pull/13468
Reviewed-by: https://github.com/davidot
Reviewed-by: https://github.com/linusg
3 changed files with 13 additions and 3 deletions
|
@ -71,6 +71,7 @@
|
|||
#include <LibJS/SourceTextModule.h>
|
||||
#include <LibLine/Editor.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <LibTextCodec/Decoder.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
@ -1653,7 +1654,16 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto file = TRY(Core::File::open(path, Core::OpenMode::ReadOnly));
|
||||
auto file_contents = file->read_all();
|
||||
auto source = StringView { file_contents };
|
||||
builder.append(source);
|
||||
|
||||
if (Utf8View { file_contents }.validate()) {
|
||||
builder.append(source);
|
||||
} else {
|
||||
auto* decoder = TextCodec::decoder_for("windows-1252");
|
||||
VERIFY(decoder);
|
||||
|
||||
auto utf8_source = TextCodec::convert_input_to_utf8_using_given_decoder_unless_there_is_a_byte_order_mark(*decoder, source);
|
||||
builder.append(utf8_source);
|
||||
}
|
||||
}
|
||||
|
||||
source_name = script_paths[0];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue