Skip to content

Commit 8ca641f

Browse files
committed
fix(regex): replace \d to [0-9] to avoid matching non-ASCII digits
1 parent 94450a6 commit 8ca641f

File tree

4 files changed

+6
-9
lines changed

4 files changed

+6
-9
lines changed

src/cli/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub enum CLIError {
2424
fn maybe_suggest_toolchain(bad_name: &str) -> String {
2525
let bad_name = &bad_name.to_ascii_lowercase();
2626
static VALID_CHANNELS: &[&str] = &["stable", "beta", "nightly"];
27-
static NUMBERED: Lazy<Regex> = Lazy::new(|| Regex::new(r"^\d+\.\d+$").unwrap());
27+
static NUMBERED: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[0-9]+\.[0-9]+$").unwrap());
2828
if NUMBERED.is_match(bad_name) {
2929
return format!(". Toolchain numbers tend to have three parts, e.g. {bad_name}.0");
3030
}

src/cli/self_update.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,8 @@ fn parse_new_rustup_version(version: String) -> String {
10861086
use once_cell::sync::Lazy;
10871087
use regex::Regex;
10881088

1089-
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"\d+.\d+.\d+[0-9a-zA-Z-]*").unwrap());
1089+
static RE: Lazy<Regex> =
1090+
Lazy::new(|| Regex::new(r"[0-9]+.[0-9]+.[0-9]+[0-9a-zA-Z-]*").unwrap());
10901091

10911092
let capture = RE.captures(&version);
10921093
let matched_version = match capture {

src/dist/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,15 @@ impl FromStr for ParsedToolchainDesc {
256256
// and an optional match of the date (2) and target (3)
257257
static TOOLCHAIN_CHANNEL_RE: Lazy<Regex> = Lazy::new(|| {
258258
Regex::new(&format!(
259-
r"^({})(?:-(\d{{4}}-\d{{2}}-\d{{2}}))?(?:-(.+))?$",
259+
r"^({})(?:-([0-9]{{4}}-[0-9]{{2}}-[0-9]{{2}}))?(?:-(.+))?$",
260260
// The channel patterns we support
261261
[
262262
"nightly",
263263
"beta",
264264
"stable",
265265
// Allow from 1.0.0 through to 9.999.99 with optional patch version
266266
// and optional beta tag
267-
r"\d{1}\.\d{1,3}(?:\.\d{1,2})?(?:-beta(?:\.\d{1,2})?)?",
267+
r"[0-9]{1}\.[0-9]{1,3}(?:\.[0-9]{1,2})?(?:-beta(?:\.[0-9]{1,2})?)?",
268268
]
269269
.join("|")
270270
))

src/toolchain/names.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,7 @@ mod tests {
480480
LIST_OSES.join("|"),
481481
LIST_ENVS.join("|")
482482
);
483-
let partial_toolchain_desc_re = format!(
484-
r"(nightly|beta|stable|\d{{1}}\.\d{{1,3}}(\.\d{{1,2}})?)(-(\d{{4}}-\d{{2}}-\d{{2}}))?{triple_re}"
485-
);
486-
487-
partial_toolchain_desc_re
483+
r"(nightly|beta|stable|[0-9]{1}(\.(0|[1-9][0-9]{0,2}))(\.(0|[1-9][0-9]{0,1}))?(-beta(\.(0|[1-9][1-9]{0,1}))?)?)(-([0-9]{4}-[0-9]{2}-[0-9]{2}))?".to_owned() + &triple_re
488484
}
489485

490486
prop_compose! {

0 commit comments

Comments
 (0)