Skip to content

Reimplemented glob stripping with regex#297

Open
egormanga wants to merge 1 commit into
rust-embedded:masterfrom
egormanga:fix/glob-regex
Open

Reimplemented glob stripping with regex#297
egormanga wants to merge 1 commit into
rust-embedded:masterfrom
egormanga:fix/glob-regex

Conversation

@egormanga
Copy link
Copy Markdown

@egormanga egormanga commented May 15, 2026

Currently, using strip patterns such as REG[ABC]_ results in panic due to bounds check, since the implementation naïvely treats them as fixed-lengthed. This logic was never correct.

This reimplements the logic using proper regex conversion, similar to that in the legacy Python version, which allows to use more elaborate patterns.

@egormanga
Copy link
Copy Markdown
Author

This is partially needed for correct building of the current master of ch32-rs. Will link its relevant PR here when ready.

Comment thread src/patch/peripheral.rs
fn strip_start(&mut self, prefix: &str) -> PatchResult {
let len = prefix.len();
let glob = globset::Glob::new(&(prefix.to_string() + "*"))?.compile_matcher();
let re = regex::Regex::new(&globset::Glob::new(prefix)?.regex().replace("(?-u)", "").replace("*", "*?").strip_suffix("$").unwrap())?;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is hard to read. Format this or better split it into two separate statements.

@burrbull
Copy link
Copy Markdown
Member

Is it? I think #49 is about significant change of syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants