Skip to content

Commit cbf2420

Browse files
committed
fix: handle legacy decomposed regex struct
1 parent 6932fbf commit cbf2420

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ tests/fixtures/confidential*
99

1010

1111
.claude
12-
.thoughts
12+
thoughts/

Cargo.lock

Lines changed: 1 addition & 1 deletion
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
@@ -1,6 +1,6 @@
11
[package]
22
name = "relayer-utils"
3-
version = "0.4.62-13"
3+
version = "0.4.62-14"
44
authors = ["Sora Suegami", "Aditya Bisht"]
55
license = "MIT"
66
edition = "2018"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"wasm:postbuild": "node build.js",
1111
"build": "npm run wasm:build && npm run wasm:postbuild"
1212
},
13-
"version": "0.4.66-5",
13+
"version": "0.4.66-6",
1414
"devDependencies": {
1515
"@types/bun": "latest",
1616
"prettier": "^3.3.3"

src/regex/wasm.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ pub fn extractSubstrIdxes(
1717
regexConfigJson: JsValue,
1818
revealPrivate: bool,
1919
) -> Result<Array, JsValue> {
20-
// Parse config from JSON
21-
let config: DecomposedRegexConfig = from_value(regexConfigJson)
22-
.map_err(|e| JsValue::from_str(&format!("Invalid config: {}", e)))?;
20+
// Try parsing as new format first, fall back to legacy format
21+
let config: DecomposedRegexConfig = match from_value::<DecomposedRegexConfig>(regexConfigJson.clone()) {
22+
Ok(cfg) => cfg,
23+
Err(_) => {
24+
// Try parsing as legacy format
25+
let legacy: crate::regex::types::LegacyDecomposedRegexConfig = from_value(regexConfigJson)
26+
.map_err(|e| JsValue::from_str(&format!("Invalid config: {}", e)))?;
27+
legacy.to_new_config(None)
28+
}
29+
};
2330

2431
// Extract indices (standalone mode - no NFAGraph)
2532
let indices = extract_substr_idxes(inputStr, &config, None, revealPrivate)
@@ -44,9 +51,16 @@ pub fn extractSubstr(
4451
regexConfigJson: JsValue,
4552
revealPrivate: bool,
4653
) -> Result<Array, JsValue> {
47-
// Parse config from JSON
48-
let config: DecomposedRegexConfig = from_value(regexConfigJson)
49-
.map_err(|e| JsValue::from_str(&format!("Invalid config: {}", e)))?;
54+
// Try parsing as new format first, fall back to legacy format
55+
let config: DecomposedRegexConfig = match from_value::<DecomposedRegexConfig>(regexConfigJson.clone()) {
56+
Ok(cfg) => cfg,
57+
Err(_) => {
58+
// Try parsing as legacy format
59+
let legacy: crate::regex::types::LegacyDecomposedRegexConfig = from_value(regexConfigJson)
60+
.map_err(|e| JsValue::from_str(&format!("Invalid config: {}", e)))?;
61+
legacy.to_new_config(None)
62+
}
63+
};
5064

5165
// Extract substrings (standalone mode - no NFAGraph)
5266
let substrings = extract_substr(inputStr, &config, None, revealPrivate)
@@ -194,4 +208,13 @@ mod tests {
194208
assert_eq!(&result[0..5], b"hello");
195209
assert_eq!(&result[5..10], &[0u8; 5]);
196210
}
211+
212+
#[test]
213+
fn test_wasm_extract_substr() {
214+
let input = "from:[email protected]";
215+
let regex_config_json = JsValue::from_str(r#"{"parts":[{"is_public":true,"regex_def":"[a-z]+@[a-z]+\\.com"}]}"#);
216+
let result = extractSubstr(input, regex_config_json, false);
217+
println!("result: {:?}", result);
218+
assert_eq!(result.unwrap(), vec!["[email protected]"]);
219+
}
197220
}

0 commit comments

Comments
 (0)