weaver_forge: sanitize_name keeps non-ASCII letters that come before the first invalid character
Describe the bug
sanitize_name in crates/weaver_forge/src/extensions/prom.rs keeps a non-ASCII letter when it comes before the first invalid character, and replaces it with _ when it comes after.
To Reproduce
A test added to the tests module of prom.rs, on main at 14d1df9:
#[test]
fn zz_repro_non_ascii() {
for n in ["café", "x.café", "café.x", "temperatur.außen", "außen.temperatur"] {
let out = sanitize_name(&n.into());
let legal = out.chars().all(|c| c.is_ascii_alphanumeric() || c == '_' || c == ':');
println!("{n:<20} -> {out:<20} legal={legal}");
}
}
$ cargo test -p weaver_forge --lib zz_repro -- --nocapture
café -> café legal=false
x.café -> x_caf_ legal=true
café.x -> café_x legal=false
temperatur.außen -> temperatur_au_en legal=true
außen.temperatur -> außen_temperatur legal=false
# rustc 1.96.1
Expected behavior
Every letter outside ASCII becomes _ wherever it sits, giving a name inside [a-zA-Z_:][a-zA-Z0-9_:]*. The weaver_forge README says these filters follow the Prometheus exporter spec, which escapes to that set (regex), and name_sanitization already expects it for €.
Additional context
The scan for the first invalid character uses is_alphanumeric(), which is Unicode, and the replacement uses is_ascii_alphanumeric(). Using the ASCII check in the scan fixes all five cases, and cargo test -p weaver_forge passes, 204 lib tests with the repro among them. It only bites names with non-ASCII letters. I can send that one-line PR.