ronantakizawa/codereview-bench huggingface dataset:
Repository: sxyazi/yazi
File: yazi-adapter/src/image.rs (Rust)

Code before:
use std::path::{Path, PathBuf};

use anyhow::{Context, Result};
use image::{ColorType, DynamicImage, ExtendedColorType, ImageDecoder, ImageEncoder, ImageError, ImageReader, ImageResult, Limits, codecs::{jpeg::JpegEncoder, png::PngEncoder}, imageops::FilterType, metadata::Orientation};
use qcms::{Profile, Transform};
use ratatui::layout::Rect;
use yazi_config::YAZI;
use yazi_fs::provider::{Provider, local::Local};

use crate::Dimension;

pub struct Image;

impl Image {
	pub async fn precache(src: PathBuf, cache: &Path) -> Result<()> {
		let (mut img, orientation, icc) = Self::decode_from(src.clone()).await?;
		let (w, h) = Self::flip_size(orientation, (YAZI.preview.max_width, YAZI.preview.max_height));

		let buf = tokio::task::spawn_blocking(move || {
			if img.width() > w || img.height() > h {
				img = img.resize(w, h, Self::filter());
			}
			if orientation != Orientation::NoTransforms {
				img.apply_orientation(orientation);
			}

			let mut buf = Vec::new();
			if img.color().has_alpha() {
				let rgba = img.into_rgba8();
				let mut encoder = PngEncoder::new(&mut buf);
				icc.map(|b| encoder.set_icc_profile(b));
				encoder.write_image(&rgba, rgba.width(), rgba.height(), ExtendedColorType::Rgba8)?;
			} else {
				let mut encoder = JpegEncoder::new_with_quality(&mut buf, YAZI.preview.image_quality);

				let mut data = img.to_rgb8().into_raw();

				// If ICC profile is present and it's not srgb, perform color transformation
				if let Some(ref icc_profile) = icc
					&& let Some(input) = Profile::new_from_slice(icc_profile, false)
					&& !input.is_sRGB()

Review comment (suggestion):
```suggestion
		let (mut img, orientation, icc) = Self::decode_from(src).await?;
```

Code after:
use std::path::{Path, PathBuf};

use anyhow::Result;
use image::{DynamicImage, ImageDecoder, ImageError, ImageReader, Limits, codecs::{jpeg::JpegEncoder, png::PngEncoder}, imageops::FilterType, metadata::Orientation};
use ratatui::layout::Rect;
use yazi_config::YAZI;
use yazi_fs::provider::{Provider, local::Local};

use crate::{Dimension, Icc};

pub struct Image;

impl Image {
	pub async fn precache(src: PathBuf, cache: &Path) -> Result<()> {
		let (mut img, orientation) = Self::decode_from(src).await?;
		let (w, h) = Self::flip_size(orientation, (YAZI.preview.max_width, YAZI.preview.max_height));

		let buf = tokio::task::spawn_blocking(move || {
			if img.width() > w || img.height() > h {
				img = img.resize(w, h, Self::filter());
			}
			if orientation != Orientation::NoTransforms {
				img.apply_orientation(orientation);
			}

			let mut buf = Vec::new();
			if img.color().has_alpha() {
				let encoder = PngEncoder::new(&mut buf);
				img.write_with_encoder(encoder)?;
			} else {
				let encoder = JpegEncoder::new_with_quality(&mut buf, YAZI.preview.image_quality);
				img.write_with_encoder(encoder)?;
			}

			Ok::<_, ImageError>(buf)
		})
		.await??;

		Ok(Local::regular(&cache).write(buf).await?)
	}
Repository: sxyazi/yazi
File: yazi-shared/src/shell/windows.rs (Rust)

Code before:
use std::borrow::Cow;

pub fn escape_os_bytes(b: &[u8]) -> Cow<'_, [u8]> {
	let quote = needs_quotes(b);
	let mut buf = Vec::with_capacity(b.len() + quote as usize * 2);

	if quote {
		buf.push(b'"');
	}

	// Loop through the string, escaping `\` only if followed by `"`.
	// And escaping `"` by doubling them.
	let mut backslashes: usize = 0;
	for &c in b {
		if c == b'\\' {
			backslashes += 1;
		} else {
			if c == b'"' {
				buf.extend((0..backslashes).map(|_| b'\\'));
				buf.push(b'"')
			} else if c == b'%' {
				buf.extend_from_slice(b"%%cd:~,");
			} else if c == b'\r' || c == b'\n' {
				buf.extend_from_slice(b"%=%");
				backslashes = 0;
				continue;
			}
			backslashes = 0;
		}
		buf.push(c);
	}

	if quote {
		buf.extend((0..backslashes).map(|_| b'\\'));
		buf.push(b'"');
	}

	buf.into()
}

#[cfg(windows)]
pub fn escape_os_str(s: &std::ffi::OsStr) -> Cow<'_, std::ffi::OsStr> {
	use crate::FromWtf8Vec;

	match escape_os_bytes(s.as_encoded_bytes()) {

Review comment (suggestion):
Missing semicolon after `buf.push(b'"')`. This will cause a compilation error. Note that the code intentionally falls through to line 30 to push the quote character a second time (for doubling), so only the semicolon needs to be added - don't add a `continue` statement.
```suggestion
				buf.push(b'"');
```

Code after:
use std::borrow::Cow;

pub fn escape_os_bytes(b: &[u8]) -> Cow<'_, [u8]> {
	let quote = needs_quotes(b);
	let mut buf = Vec::with_capacity(b.len() + quote as usize * 2);

	if quote {
		buf.push(b'"');
	}

	// Loop through the string, escaping `\` only if followed by `"`.
	// And escaping `"` by doubling them.
	let mut backslashes: usize = 0;
	for &c in b {
		if c == b'\\' {
			backslashes += 1;
		} else {
			if c == b'"' {
				buf.extend((0..backslashes).map(|_| b'\\'));
				buf.push(b'"');
			} else if c == b'%' {
				buf.extend_from_slice(b"%%cd:~,");
			} else if c == b'\r' || c == b'\n' {
				buf.extend_from_slice(b"%=%");
				backslashes = 0;
				continue;
			}
			backslashes = 0;
		}
		buf.push(c);
	}

	if quote {
		buf.extend((0..backslashes).map(|_| b'\\'));
		buf.push(b'"');
	}

	buf.into()
}

#[cfg(windows)]
pub fn escape_os_str(s: &std::ffi::OsStr) -> Cow<'_, std::ffi::OsStr> {
	use crate::FromWtf8Vec;

	match escape_os_bytes(s.as_encoded_bytes()) {
Repository: sxyazi/yazi
File: yazi-shared/src/shell/windows.rs (Rust)

Code before:
use std::borrow::Cow;

pub fn escape_os_bytes(b: &[u8]) -> Cow<'_, [u8]> {
	let quote = needs_quotes(b);
	let mut buf = Vec::with_capacity(b.len() + quote as usize * 2);

	if quote {
		buf.push(b'"');
	}

	// Loop through the string, escaping `\` only if followed by `"`.
	// And escaping `"` by doubling them.
	let mut backslashes: usize = 0;
	for &c in b {
		if c == b'\\' {
			backslashes += 1;
		} else {
			if c == b'"' {
				buf.extend((0..backslashes).map(|_| b'\\'));
				buf.push(b'"')
			} else if c == b'%' {
				buf.extend_from_slice(b"%%cd:~,");
			} else if c == b'\r' || c == b'\n' {
				buf.extend_from_slice(b"%=%");
				backslashes = 0;
				continue;
			}
			backslashes = 0;
		}
		buf.push(c);
	}

	if quote {
		buf.extend((0..backslashes).map(|_| b'\\'));
		buf.push(b'"');
	}

	buf.into()
}

#[cfg(windows)]
pub fn escape_os_str(s: &std::ffi::OsStr) -> Cow<'_, std::ffi::OsStr> {
	use crate::FromWtf8Vec;

	match escape_os_bytes(s.as_encoded_bytes()) {
		Cow::Borrowed(_) => Cow::Borrowed(s),
		Cow::Owned(v) => std::ffi::OsString::from_wtf8_vec(v).expect("valid WTF-8").into(),

Review comment (bug):
The `%` escaping logic appears incorrect. The code adds `%%cd:~,` (line 22) but then also pushes the original `%` character (line 30), resulting in `%%cd:~,%`. This doesn't follow the pattern of other escape sequences. Either the `%` should not be pushed again (add `continue;` after line 22), or the escaping strategy needs revision.
```suggestion
				buf.extend_from_slice(b"%%cd:~,");
				continue;
```

Code after:
use std::borrow::Cow;

pub fn escape_os_bytes(b: &[u8]) -> Cow<'_, [u8]> {
	let quote = needs_quotes(b);
	let mut buf = Vec::with_capacity(b.len() + quote as usize * 2);

	if quote {
		buf.push(b'"');
	}

	// Loop through the string, escaping `\` only if followed by `"`.
	// And escaping `"` by doubling them.
	let mut backslashes: usize = 0;
	for &c in b {
		if c == b'\\' {
			backslashes += 1;
		} else {
			if c == b'"' {
				buf.extend((0..backslashes).map(|_| b'\\'));
				buf.push(b'"');
			} else if c == b'%' {
				buf.extend_from_slice(b"%%cd:~,");
			} else if c == b'\r' || c == b'\n' {
				buf.extend_from_slice(b"%=%");
				backslashes = 0;
				continue;
			}
			backslashes = 0;
		}
		buf.push(c);
	}

	if quote {
		buf.extend((0..backslashes).map(|_| b'\\'));
		buf.push(b'"');
	}

	buf.into()
}

#[cfg(windows)]
pub fn escape_os_str(s: &std::ffi::OsStr) -> Cow<'_, std::ffi::OsStr> {
	use crate::FromWtf8Vec;

	match escape_os_bytes(s.as_encoded_bytes()) {
		Cow::Borrowed(_) => Cow::Borrowed(s),
		Cow::Owned(v) => std::ffi::OsString::from_wtf8_vec(v).expect("valid WTF-8").into(),
Repository: sxyazi/yazi
File: yazi-shared/src/shell/windows.rs (Rust)

Code before:
use std::borrow::Cow;

pub fn escape_os_bytes(b: &[u8]) -> Cow<'_, [u8]> {
	let quote = needs_quotes(b);
	let mut buf = Vec::with_capacity(b.len() + quote as usize * 2);

	if quote {
		buf.push(b'"');
	}

	// Loop through the string, escaping `\` only if followed by `"`.
	// And escaping `"` by doubling them.
	let mut backslashes: usize = 0;
	for &c in b {
		if c == b'\\' {
			backslashes += 1;
		} else {
			if c == b'"' {
				buf.extend((0..backslashes).map(|_| b'\\'));
				buf.push(b'"')
			} else if c == b'%' {
				buf.extend_from_slice(b"%%cd:~,");
			} else if c == b'\r' || c == b'\n' {
				buf.extend_from_slice(b"%=%");
				backslashes = 0;
				continue;
			}
			backslashes = 0;
		}
		buf.push(c);
	}

	if quote {
		buf.extend((0..backslashes).map(|_| b'\\'));
		buf.push(b'"');
	}

	buf.into()
}

#[cfg(windows)]
pub fn escape_os_str(s: &std::ffi::OsStr) -> Cow<'_, std::ffi::OsStr> {
	use crate::FromWtf8Vec;

	match escape_os_bytes(s.as_encoded_bytes()) {
		Cow::Borrowed(_) => Cow::Borrowed(s),
		Cow::Owned(v) => std::ffi::OsString::from_wtf8_vec(v).expect("valid WTF-8").into(),

Review comment (security):
The `%` escaping behavior is not covered by tests. Given the complexity of this escape sequence and the Windows cmd.exe behavior with `/S` flag, test cases should be added to verify that `%` characters are correctly escaped, especially since this appears to be new functionality.

Code after:
use std::borrow::Cow;

pub fn escape_os_bytes(b: &[u8]) -> Cow<'_, [u8]> {
	let quote = needs_quotes(b);
	let mut buf = Vec::with_capacity(b.len() + quote as usize * 2);

	if quote {
		buf.push(b'"');
	}

	// Loop through the string, escaping `\` only if followed by `"`.
	// And escaping `"` by doubling them.
	let mut backslashes: usize = 0;
	for &c in b {
		if c == b'\\' {
			backslashes += 1;
		} else {
			if c == b'"' {
				buf.extend((0..backslashes).map(|_| b'\\'));
				buf.push(b'"');
			} else if c == b'%' {
				buf.extend_from_slice(b"%%cd:~,");
			} else if c == b'\r' || c == b'\n' {
				buf.extend_from_slice(b"%=%");
				backslashes = 0;
				continue;
			}
			backslashes = 0;
		}
		buf.push(c);
	}

	if quote {
		buf.extend((0..backslashes).map(|_| b'\\'));
		buf.push(b'"');
	}

	buf.into()
}

#[cfg(windows)]
pub fn escape_os_str(s: &std::ffi::OsStr) -> Cow<'_, std::ffi::OsStr> {
	use crate::FromWtf8Vec;

	match escape_os_bytes(s.as_encoded_bytes()) {
		Cow::Borrowed(_) => Cow::Borrowed(s),
		Cow::Owned(v) => std::ffi::OsString::from_wtf8_vec(v).expect("valid WTF-8").into(),
Repository: sxyazi/yazi
File: yazi-shared/src/shell/windows.rs (Rust)

Code before:
use std::borrow::Cow;

pub fn escape_os_bytes(b: &[u8]) -> Cow<'_, [u8]> {
	let quote = needs_quotes(b);
	let mut buf = Vec::with_capacity(b.len() + quote as usize * 2);

	if quote {
		buf.push(b'"');
	}

	// Loop through the string, escaping `\` only if followed by `"`.
	// And escaping `"` by doubling them.
	let mut backslashes: usize = 0;
	for &c in b {
		if c == b'\\' {
			backslashes += 1;
		} else {
			if c == b'"' {
				buf.extend((0..backslashes).map(|_| b'\\'));
				buf.push(b'"')
			} else if c == b'%' {
				buf.extend_from_slice(b"%%cd:~,");
			} else if c == b'\r' || c == b'\n' {
				buf.extend_from_slice(b"%=%");
				backslashes = 0;
				continue;
			}
			backslashes = 0;
		}
		buf.push(c);
	}

	if quote {
		buf.extend((0..backslashes).map(|_| b'\\'));
		buf.push(b'"');
	}

	buf.into()
}

#[cfg(windows)]
pub fn escape_os_str(s: &std::ffi::OsStr) -> Cow<'_, std::ffi::OsStr> {
	use crate::FromWtf8Vec;

	match escape_os_bytes(s.as_encoded_bytes()) {
		Cow::Borrowed(_) => Cow::Borrowed(s),
		Cow::Owned(v) => std::ffi::OsString::from_wtf8_vec(v).expect("valid WTF-8").into(),
	}
}

Review comment (security):
The newline escaping behavior (replacing `\r` and `\n` with `%=%`) is not covered by tests. Test cases should be added to verify that newline characters are correctly escaped using the `%=%` sequence.

Code after:
use std::borrow::Cow;

pub fn escape_os_bytes(b: &[u8]) -> Cow<'_, [u8]> {
	let quote = needs_quotes(b);
	let mut buf = Vec::with_capacity(b.len() + quote as usize * 2);

	if quote {
		buf.push(b'"');
	}

	// Loop through the string, escaping `\` only if followed by `"`.
	// And escaping `"` by doubling them.
	let mut backslashes: usize = 0;
	for &c in b {
		if c == b'\\' {
			backslashes += 1;
		} else {
			if c == b'"' {
				buf.extend((0..backslashes).map(|_| b'\\'));
				buf.push(b'"');
			} else if c == b'%' {
				buf.extend_from_slice(b"%%cd:~,");
			} else if c == b'\r' || c == b'\n' {
				buf.extend_from_slice(b"%=%");
				backslashes = 0;
				continue;
			}
			backslashes = 0;
		}
		buf.push(c);
	}

	if quote {
		buf.extend((0..backslashes).map(|_| b'\\'));
		buf.push(b'"');
	}

	buf.into()
}

#[cfg(windows)]
pub fn escape_os_str(s: &std::ffi::OsStr) -> Cow<'_, std::ffi::OsStr> {
	use crate::FromWtf8Vec;

	match escape_os_bytes(s.as_encoded_bytes()) {
		Cow::Borrowed(_) => Cow::Borrowed(s),
		Cow::Owned(v) => std::ffi::OsString::from_wtf8_vec(v).expect("valid WTF-8").into(),
	}
}
Repository: sxyazi/yazi
File: yazi-shared/src/shell/windows.rs (Rust)

Code before:
		];

		for &(input, expected) in cases {
			let escaped = escape_os_bytes(input);
			assert_eq!(escaped, expected, "Failed to escape: {:?}", String::from_utf8_lossy(input));
		}
	}

	#[cfg(windows)]
	#[test]
	fn test_escape_os_str() {
		use std::{ffi::OsString, os::windows::ffi::OsStringExt};

		#[rustfmt::skip]
		let cases: &[(OsString, OsString)] = &[
			// Surrogate pairs and special characters
			(
				OsString::from_wide(&[0x1055, 0x006e, 0x0069, 0x0063, 0x006f, 0x0064, 0x0065]),
				OsString::from_wide(&[0x1055, 0x006e, 0x0069, 0x0063, 0x006f, 0x0064, 0x0065]),
			),
			// Surrogate pair with quotes
			(
				OsString::from_wide(&[0xd801, 0x006e, 0x0069, 0x0063, 0x006f, 0x0064, 0x0065]),
				OsString::from_wide(&[0xd801, 0x006e, 0x0069, 0x0063, 0x006f, 0x0064, 0x0065]),
			),
		];

		for (input, expected) in cases {
			let escaped = escape_os_str(&input);
			assert_eq!(&*escaped, expected, "Failed to escape: {:?}", input.to_string_lossy());
		}
	}
}


Review comment (bug):
The test expectation for unpaired surrogates appears incorrect. The old implementation (being removed) quoted strings containing unpaired surrogates like `0xd801` because they failed `char::from_u32()`. The new byte-based implementation doesn't detect unpaired surrogates (they're non-ASCII bytes `0xED 0xA0 0x81` in WTF-8), so `needs_quotes` returns false. The test should expect quotes around this invalid Unicode sequence, or `needs_quotes` should be updated to detect WTF-8 encoded surrogates.
```suggestion
				OsString::from_wide(&[b'"' as u16, 0xd801, 0x006e, 0x0069, 0x0063, 0x006f, 0x0064, 0x0065, b'"' as u16]),
```

Code after:
			// Unicode characters
			("이것은 테스트".as_bytes(), r#""이것은 테스트""#.as_bytes()),
		];

		for &(input, expected) in cases {
			let escaped = escape_os_bytes(input);
			assert_eq!(escaped, expected, "Failed to escape: {:?}", String::from_utf8_lossy(input));
		}
	}

	#[cfg(windows)]
	#[test]
	fn test_escape_os_str() {
		use std::{ffi::OsString, os::windows::ffi::OsStringExt};

		#[rustfmt::skip]
		let cases: &[(OsString, OsString)] = &[
			// Surrogate pairs and special characters
			(
				OsString::from_wide(&[0x1055, 0x006e, 0x0069, 0x0063, 0x006f, 0x0064, 0x0065]),
				OsString::from_wide(&[0x1055, 0x006e, 0x0069, 0x0063, 0x006f, 0x0064, 0x0065]),
			),
			// Surrogate pair with quotes
			(
				OsString::from_wide(&[0xd801, 0x006e, 0x0069, 0x0063, 0x006f, 0x0064, 0x0065]),
				OsString::from_wide(&[0xd801, 0x006e, 0x0069, 0x0063, 0x006f, 0x0064, 0x0065]),
			),
		];

		for (input, expected) in cases {
			let escaped = escape_os_str(&input);
			assert_eq!(&*escaped, expected, "Failed to escape: {:?}", input.to_string_lossy());
		}
	}
}
Repository: sxyazi/yazi
File: yazi-sftp/src/session.rs (Rust)

Code before:
						};

						if let Ok(packet) = crate::from_bytes(&buf)
							&& let Some(cb) = me_.callback.lock().remove(&packet.id())
						{
							cb.send(packet).ok();
						}
					}
					_ = me_.tx.closed() => break,
				}
			}
		});

		me
	}

	pub async fn send<'a, I, O>(&self, input: I) -> Result<O, Error>
	where
		I: Into<Packet<'a>> + Serialize,
		O: TryFrom<Packet<'static>, Error = Error> + 'static,
	{
		match self.send_sync(input)?.await? {
			Packet::Status(status) if TypeId::of::<O>() != TypeId::of::<responses::Status>() => {
				Err(Error::Status(status))
			}
			response => response.try_into(),
		}
	}

	pub fn send_sync<'a, I>(&self, input: I) -> Result<oneshot::Receiver<Packet<'static>>, Error>
	where
		I: Into<Packet<'a>> + Serialize,
	{
		let mut request: Packet = input.into();
		if request.id() == 0 {
			request = request.with_id(self.id.next());
		}

		let (tx, rx) = oneshot::channel();
		self.callback.lock().insert(request.id(), tx);
		self.tx.send(crate::to_bytes(request)?)?;

		Ok(rx)
	}

	pub fn is_closed(&self) -> bool { self.tx.is_closed() }
}


Review comment (performance):
[nitpick] The timeout duration is hardcoded to 30 seconds. Consider making this configurable through a Session parameter or constant to allow users to adjust the timeout based on their needs (e.g., slower connections might need longer timeouts).

Code after:
								me_.tx.send(vec![]).ok();
								break;
							},
							Err(_) => continue,
						};

						if let Ok(packet) = crate::from_bytes(&buf)
							&& let Some(cb) = me_.callback.lock().remove(&packet.id())
						{
							cb.send(packet).ok();
						}
					}
					_ = me_.tx.closed() => break,
				}
			}
		});

		me
	}

	pub async fn send<'a, I, O>(self: &Arc<Self>, input: I) -> Result<O, Error>
	where
		I: Into<Packet<'a>> + Serialize,
		O: TryFrom<Packet<'static>, Error = Error> + 'static,
	{
		match timeout(Duration::from_secs(30), self.send_sync(input)?).await?? {
			Packet::Status(status) if TypeId::of::<O>() != TypeId::of::<responses::Status>() => {
				Err(Error::Status(status))
			}
			response => response.try_into(),
		}
	}

	pub fn send_sync<'a, I>(self: &Arc<Self>, input: I) -> Result<Receiver, Error>
	where
		I: Into<Packet<'a>> + Serialize,
	{
		let mut request: Packet = input.into();
		if request.id() == 0 {
			request = request.with_id(self.id.next());
		}

		let id = request.id();
		let (tx, rx) = oneshot::channel();

		self.callback.lock().insert(id, tx);
		self.tx.send(crate::to_bytes(request)?)?;
		Ok(Receiver::new(self, id, rx))
	}

	pub fn is_closed(self: &Arc<Self>) -> bool { self.tx.is_closed() }
Repository: sxyazi/yazi
File: yazi-plugin/preset/plugins/mime-local.lua (Lua)

Code before:
	end

	local child, err = cmd:spawn()
	if not child then
		local e = Error.fs {
			kind = err.kind or "Other",
			code = err.code,
			message = string.format("Failed to start `%s`, error: %s", bin, err),
		}
		return nil, e
	elseif windows then
		child:write_all(table.concat(paths, "\n"))
		child:flush()
		ya.drop(child:take_stdin())
	end

	return child
end

function M.placeholder(err, urls, paths)
	if err.kind ~= "NotFound" then
		return
	end

	local updates = {}
	for i = 1, math.max(#urls, #paths) do
		updates[urls[i] or paths[i]] = "null/file1-not-found"
	end

	ya.emit("update_mimes", { updates = updates })
end

return M


Review comment (suggestion):
The loop iterates up to `math.max(#urls, #paths)`, but this can cause nil access when one array is shorter than the other. If `#urls < #paths`, then `urls[i]` will be nil for indices beyond `#urls`, and if both are nil at index `i`, the expression `urls[i] or paths[i]` would try to use `paths[i]` which might also be nil. The logic should ensure valid indices for both arrays. Consider using separate loops or bounds checking: `for i = 1, math.min(math.max(#urls, #paths), math.max(1, #urls > 0 and #urls or #paths)) do` or simply `for i = 1, #paths do` since paths is always populated based on the fetch function logic.
```suggestion
	for i = 1, #paths do
```

Code after:
	end

	local child, err = cmd:spawn()
	if not child then
		local e = Error.fs {
			kind = err.kind or "Other",
			code = err.code,
			message = string.format("Failed to start `%s`, error: %s", bin, err),
		}
		return nil, e
	elseif windows then
		child:write_all(table.concat(paths, "\n"))
		child:flush()
		ya.drop(child:take_stdin())
	end

	return child
end

function M.placeholder(err, urls, paths)
	if err.kind ~= "NotFound" then
		return
	end

	local updates = {}
	for i = 1, #paths do
		updates[urls[i] or paths[i]] = "null/file1-not-found"
	end

	ya.emit("update_mimes", { updates = updates })
end

return M
Repository: sxyazi/yazi
File: yazi-actor/src/cmp/trigger.rs (Rust)

Code before:

		compare("/foo", "/", "foo");
		compare("//foo", "/", "foo");
		compare("///foo", "/", "foo");

		compare("/foo/", "/foo/", "");
		compare("//foo/", "/foo/", "");
		compare("/foo/bar", "/foo/", "bar");
		compare("///foo/bar", "/foo/", "bar");
	}

	#[cfg(windows)]
	#[test]
	fn test_split() {
		yazi_fs::init();
		compare("foo", "", "foo");
		compare(r"foo\", r"foo\", "");
		compare(r"foo\bar", r"foo\", "bar");
		compare(r"foo\bar\", r"foo\bar\", "");
		compare(r"C:\", r"C:\", "");
		compare(r"C:\foo", r"C:\", "foo");
		compare(r"C:\foo\", r"C:\foo\", "");
		compare(r"C:\foo\bar", r"C:\foo\", "bar");
	}
}


Review comment (bug):
Missing initialization call `yazi_shared::init_tests()` in the Windows test. The Unix test at line 115 includes this call, but the Windows test is missing it. This inconsistency could lead to test failures on Windows if the initialization is required.

Code after:
		compare(" ", "", " ");

		compare("/", "/", "");
		compare("//", "/", "");
		compare("///", "/", "");

		compare("/foo", "/", "foo");
		compare("//foo", "/", "foo");
		compare("///foo", "/", "foo");

		compare("/foo/", "/foo/", "");
		compare("//foo/", "/foo/", "");
		compare("/foo/bar", "/foo/", "bar");
		compare("///foo/bar", "/foo/", "bar");

		CWD.set(&"sftp://test/".parse::<UrlBuf>().unwrap(), || {});
		compare("sftp://test/a", "sftp://test/", "a");
		compare("sftp://test//a", "sftp://test:0//", "a");
		compare("sftp://test2/a", "sftp://test2/", "a");
		compare("sftp://test2//a", "sftp://test2:0//", "a");
	}

	#[cfg(windows)]
	#[test]
	fn test_split() {
		yazi_fs::init();
		compare("foo", "", "foo");

		compare(r"foo\", r"foo\", "");
		compare(r"foo\bar", r"foo\", "bar");
		compare(r"foo\bar\", r"foo\bar\", "");

		compare(r"C:\", r"C:\", "");
		compare(r"C:\foo", r"C:\", "foo");
		compare(r"C:\foo\", r"C:\foo\", "");
		compare(r"C:\foo\bar", r"C:\foo\", "bar");
	}
}