Skip to content

Commit 87fa29e

Browse files
committed
objdiff-wasm: Fix symbol filtering
regex crate needed the `unicode-case` feature
1 parent 42d4c38 commit 87fa29e

File tree

7 files changed

+76
-41
lines changed

7 files changed

+76
-41
lines changed

Cargo.lock

Lines changed: 49 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ strip = "debuginfo"
1414
codegen-units = 1
1515

1616
[workspace.package]
17-
version = "3.0.0-beta.2"
17+
version = "3.0.0-beta.3"
1818
authors = ["Luke Street <luke@street.dev>"]
1919
edition = "2024"
2020
license = "MIT OR Apache-2.0"

objdiff-core/src/diff/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ pub fn instruction_hover(
563563
out
564564
}
565565

566-
#[derive(Copy, Clone)]
566+
#[derive(Debug, Copy, Clone)]
567567
pub enum SymbolFilter<'a> {
568568
None,
569569
Search(&'a Regex),

objdiff-wasm/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ std = ["objdiff-core/std"]
2424

2525
[dependencies]
2626
log = { version = "0.4", default-features = false }
27-
regex = { version = "1.11", default-features = false }
27+
regex = { version = "1.11", default-features = false, features = ["unicode-case"] }
2828

2929
[dependencies.objdiff-core]
3030
path = "../objdiff-core"
@@ -35,7 +35,7 @@ features = ["arm", "arm64", "mips", "ppc", "x86", "dwarf"]
3535
talc = { version = "4.4", default-features = false, features = ["lock_api"] }
3636

3737
[target.'cfg(target_os = "wasi")'.dependencies]
38-
wit-bindgen = { version = "0.39", default-features = false, features = ["macros"] }
38+
wit-bindgen = { version = "0.40", default-features = false, features = ["macros"] }
3939

4040
[build-dependencies]
4141
wit-deps = "0.5"

objdiff-wasm/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

objdiff-wasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "objdiff-wasm",
3-
"version": "3.0.0-beta.2",
3+
"version": "3.0.0-beta.3",
44
"description": "A local diffing tool for decompilation projects.",
55
"author": {
66
"name": "Luke Street",

objdiff-wasm/src/api.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use alloc::{
88
use core::cell::RefCell;
99

1010
use objdiff_core::{diff, obj};
11-
use regex::RegexBuilder;
11+
use regex::{Regex, RegexBuilder};
1212

1313
use super::logging;
1414

@@ -86,19 +86,31 @@ impl GuestDiff for Component {
8686
}
8787
}
8888

89+
fn build_regex(s: &str) -> Option<Regex> {
90+
if s.is_empty() {
91+
return None;
92+
}
93+
let e = match RegexBuilder::new(s).case_insensitive(true).build() {
94+
Ok(regex) => return Some(regex),
95+
Err(e) => e,
96+
};
97+
// Use the string as a literal if the regex fails to compile
98+
let escaped = regex::escape(s);
99+
if let Ok(regex) = RegexBuilder::new(&escaped).case_insensitive(true).build() {
100+
return Some(regex);
101+
}
102+
// Use the original error if the escaped string also fails
103+
log::warn!("Failed to compile regex: {}", e);
104+
None
105+
}
106+
89107
impl GuestDisplay for Component {
90108
fn display_sections(
91109
diff: ObjectDiffBorrow,
92110
filter: SymbolFilter,
93111
config: DisplayConfig,
94112
) -> Vec<SectionDisplay> {
95-
let regex = filter.regex.as_ref().and_then(|s| {
96-
RegexBuilder::new(s).case_insensitive(true).build().ok().or_else(|| {
97-
// Use the string as a literal if the regex fails to compile
98-
let escaped = regex::escape(s);
99-
RegexBuilder::new(&escaped).case_insensitive(true).build().ok()
100-
})
101-
});
113+
let regex = filter.regex.as_deref().and_then(build_regex);
102114
let filter = if let Some(mapping) = filter.mapping {
103115
diff::display::SymbolFilter::Mapping(mapping as usize, regex.as_ref())
104116
} else if let Some(regex) = &regex {

0 commit comments

Comments
 (0)