aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/io/console_io.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-02 06:30:17 +0900
committernsfisis <nsfisis@gmail.com>2026-08-02 06:30:17 +0900
commitee5025bb27862a7d2231911c08e1e0e1fa7dab20 (patch)
tree24a427d8f888bcb63a60b981cf7b9c0ee0dd35ad /crates/shirabe/src/io/console_io.rs
parent4a220b09967f84f830db029501dbef6efc4ee9f9 (diff)
downloadphp-shirabe-ee5025bb27862a7d2231911c08e1e0e1fa7dab20.tar.gz
php-shirabe-ee5025bb27862a7d2231911c08e1e0e1fa7dab20.tar.zst
php-shirabe-ee5025bb27862a7d2231911c08e1e0e1fa7dab20.zip
refactor(console-io): make ensure_valid_utf8 a no-op, drop iconv shim
Rust's &str is always valid UTF-8, so the mbstring/iconv sanitization chain can never trigger. Reduce it to a no-op with a TODO(phase-c) marker: once the codebase strictly separates Vec<u8> from String, this should take &[u8] and convert lossily. This removes the last caller of the php-shim iconv(), so delete it as well. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/io/console_io.rs')
-rw-r--r--crates/shirabe/src/io/console_io.rs29
1 files changed, 5 insertions, 24 deletions
diff --git a/crates/shirabe/src/io/console_io.rs b/crates/shirabe/src/io/console_io.rs
index de6fdede..cf488855 100644
--- a/crates/shirabe/src/io/console_io.rs
+++ b/crates/shirabe/src/io/console_io.rs
@@ -7,7 +7,6 @@ use crate::io::IOInterfaceImmutable;
use crate::io::IOInterfaceMutable;
use crate::io::io_interface;
use crate::question::StrictConfirmationQuestion;
-use crate::util::Silencer;
use indexmap::IndexMap;
use indexmap::indexmap;
use shirabe_external_packages::composer::pcre::Preg;
@@ -25,8 +24,8 @@ use shirabe_external_packages::symfony::console::question::ChoiceQuestion;
use shirabe_external_packages::symfony::console::question::Question;
use shirabe_external_packages::symfony::console::question::QuestionInterface;
use shirabe_php_shim::{
- PhpMixed, array_search, function_exists, implode, in_array, is_array, is_string,
- mb_check_encoding, mb_convert_encoding, microtime, str_repeat, strip_tags, strlen,
+ PhpMixed, array_search, implode, in_array, is_array, is_string, microtime, str_repeat,
+ strip_tags, strlen,
};
/// The Input/Output helper.
@@ -313,28 +312,10 @@ impl ConsoleIO {
}
/// Ensures a string is valid UTF-8, replacing invalid byte sequences with '?'
+ // TODO(phase-c): PHP sanitizes invalid byte sequences here, but `&str` is always valid UTF-8
+ // so this is a no-op for now. The codebase does not yet strictly distinguish `Vec<u8>` from
+ // `String`; once it does, this should take `&[u8]` and lossily convert it to `String`.
fn ensure_valid_utf8(string: &str) -> String {
- // Quick check: if string is already valid UTF-8, return as-is
- if function_exists("mb_check_encoding") && mb_check_encoding(string, "UTF-8") {
- return string.to_string();
- }
-
- // Use mb_convert_encoding to replace invalid sequences with '?'
- // This makes it visible when data quality issues occur
- if function_exists("mb_convert_encoding") {
- return mb_convert_encoding(string.as_bytes().to_vec(), "UTF-8", "UTF-8");
- }
-
- // Fallback to iconv if mbstring unavailable
- if function_exists("iconv") {
- let cleaned =
- Silencer::call(|| Ok(shirabe_php_shim::iconv("UTF-8", "UTF-8//TRANSLIT", string)));
- if let Ok(Some(c)) = cleaned {
- return c;
- }
- }
-
- // Last resort: return as-is (should never happen - Composer requires mbstring OR iconv)
string.to_string()
}