Skip to content
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

lscpu: Ensure regex behaves correctly with multi-line input #219

Merged
merged 1 commit into from
Feb 12, 2025
Merged
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
7 changes: 5 additions & 2 deletions src/uu/lscpu/src/lscpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// file that was distributed with this source code.

use clap::{crate_version, Arg, ArgAction, Command};
use regex::Regex;
use regex::RegexBuilder;
use serde::Serialize;
use std::{fs, str::FromStr};
use sysinfo::System;
Expand Down Expand Up @@ -64,7 +64,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// Add more CPU information here...

if let Ok(contents) = fs::read_to_string("/proc/cpuinfo") {
let re = Regex::new(r"^model name\s+:\s+(.*)$").unwrap();
let re = RegexBuilder::new(r"^model name\s+:\s+(.*)$")
.multi_line(true)
.build()
.unwrap();
// Assuming all CPUs have the same model name
if let Some(cap) = re.captures_iter(&contents).next() {
cpu_infos.push("Model name", &cap[1]);
Expand Down