@@ -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