Skip to content

tidy: check for invalid file names #143957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/tools/tidy/src/filenames.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! Tidy check to ensure that there are no filenames containing forbidden characters
//! checked into the source tree by accident:
//! - Non-UTF8 filenames
//! - Control characters such as CR or TAB
//! - Filenames containing ":" as they are not supported on Windows
//!
//! Only files added to git are checked, as it may be acceptable to have temporary
//! invalid filenames in the local directory during development.

use std::path::Path;
use std::process::Command;

pub fn check(root_path: &Path, bad: &mut bool) {
let stat_output = Command::new("git")
.arg("-C")
.arg(root_path)
.args(["ls-files", "-z"])
.output()
.unwrap()
.stdout;
for filename in stat_output.split(|&b| b == 0) {
match str::from_utf8(filename) {
Err(_) => tidy_error!(
bad,
r#"non-UTF8 file names are not supported: "{}""#,
String::from_utf8_lossy(filename),
),
Ok(name) if name.chars().any(|c| c.is_control()) => tidy_error!(
bad,
r#"control characters are not supported in file names: "{}""#,
String::from_utf8_lossy(filename),
),
Ok(name) if name.contains(':') => tidy_error!(
bad,
r#"":" is not supported in file names because of Windows compatibility: "{name}""#,
),
_ => (),
}
}
}
1 change: 1 addition & 0 deletions src/tools/tidy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ pub mod error_codes;
pub mod ext_tool_checks;
pub mod extdeps;
pub mod features;
pub mod filenames;
pub mod fluent_alphabetical;
pub mod fluent_period;
mod fluent_used;
Expand Down
2 changes: 2 additions & 0 deletions src/tools/tidy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ fn main() {

check!(triagebot, &root_path);

check!(filenames, &root_path);

let collected = {
drain_handles(&mut handles);

Expand Down
Loading