[PRISM] Implicitly change encoding when a UTF-8 BOM is found

This commit is contained in:
Kevin Newton 2024-03-27 13:46:00 -04:00
Родитель ab2ee308aa
Коммит 39606f36e3
3 изменённых файлов: 7 добавлений и 3 удалений

Просмотреть файл

@ -19251,6 +19251,11 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm
if (size >= 3 && source[0] == 0xef && source[1] == 0xbb && source[2] == 0xbf) {
parser->current.end += 3;
parser->encoding_comment_start += 3;
if (parser->encoding != PM_ENCODING_UTF_8_ENTRY) {
parser->encoding = PM_ENCODING_UTF_8_ENTRY;
if (parser->encoding_changed_callback != NULL) parser->encoding_changed_callback(parser);
}
}
// If the first two bytes of the source are a shebang, then we'll indicate

Просмотреть файл

@ -8431,12 +8431,12 @@ pm_parse_process_error(const pm_parse_result_t *result)
);
if (valid_utf8) {
pm_parser_errors_format(&result->parser, &result->parser.error_list, &buffer, rb_stderr_tty_p(), true);
pm_parser_errors_format(parser, &parser->error_list, &buffer, rb_stderr_tty_p(), true);
}
else {
for (const pm_diagnostic_t *error = head; error != NULL; error = (pm_diagnostic_t *) error->node.next) {
if (error != head) pm_buffer_append_byte(&buffer, '\n');
pm_buffer_append_format(&buffer, "%.*s:%" PRIi32 ": %s", (int) pm_string_length(filepath), pm_string_source(filepath), (int32_t) pm_location_line_number(&result->parser, &error->location), error->message);
pm_buffer_append_format(&buffer, "%.*s:%" PRIi32 ": %s", (int) pm_string_length(filepath), pm_string_source(filepath), (int32_t) pm_location_line_number(parser, &error->location), error->message);
}
}

Просмотреть файл

@ -5,5 +5,4 @@ exclude(:test_shareable_constant_value_simple, "ractor support")
exclude(:test_shareable_constant_value_unfrozen, "ractor support")
exclude(:test_shareable_constant_value_unshareable_literal, "ractor support")
exclude(:test_unused_variable, "missing warning")
exclude(:test_utf8_bom, "incorrect error")
exclude(:test_void_expr_stmts_value, "missing warning")