Permalink
Browse files

fix new regexp support

  • Loading branch information...
1 parent f0b4405 commit b6fac57ac85777798f036fd3f4ac52a7e8a2291f @nniclausse nniclausse committed Aug 18, 2010
View
@@ -34,7 +34,7 @@
-define(DEF_REGEXP_DYNVAR_END, "(\"|') ([^>]* )?value=(\"|')\\([^(\"|')]*\\)(\"|')").%'
-define(DEF_RE_DYNVAR_BEGIN, "name=[\"']").%'
--define(DEF_RE_DYNVAR_END, "[\"'] ([^>]* )?value=[\"']([^\"']*)[\"']").%'
+-define(DEF_RE_DYNVAR_END, "[\"'] (?:[^>]* )?value=[\"']([^\"']*)[\"']").%'
-record(config, {
name,
@@ -134,6 +134,16 @@ ifalias_test() ->
Res=ts_ip_scan:get_intf_aliases("lo"),
?assertEqual([{127,0,0,1}],Res).
+encode_test() ->
+ Encoded="ts_encoded_47myfilepath_47toto_47titi_58sdfsdf_45sdfsdf_44aa_47",
+ Str="/myfilepath/toto/titi:sdfsdf-sdfsdf,aa/",
+ ?assertEqual(Encoded,ts_config_server:encode_filename(Str)).
+
+decode_test() ->
+ Encoded="ts_encoded_47myfilepath_47toto_47titi_58sdfsdf_45sdfsdf_44aa_47",
+ Str="/myfilepath/toto/titi:sdfsdf-sdfsdf,aa/",
+ ?assertEqual(Str,ts_config_server:decode_filename(Encoded)).
+
myset_env()->
myset_env(0).
myset_env(Level)->
@@ -224,6 +224,25 @@ parse_subst1_re_test() ->
[{Name,Value}] = ts_search:parse_dynvar([{re, 'jsf_tree_64', Regexp }],list_to_binary(Data)),
?assertMatch("H4sIAAAAAAAAAK1VS2/TQBBeo+kalCKAA", ts_search:subst("%%_jsf_tree_64%%",[{Name,Value}])).
+parse_subst2_re_test() ->
+ myset_env(),
+ Data="<HTML>
+ <HEAD>
+ <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>
+ <META NAME='author' CONTENT='Test'>
+ <TITLE>4DOM version 0.10.2</TITLE>
+ </HEAD>
+ <BODY>
+ <H1>4DOM version 0.10.2</H1>
+ <H3></H3>
+ <P>4Suite <A HREF='http://4Suite.org/getdoc.epy?file=4Suite/'>http://FourThought.com/4Suite<
+/A>
+ </P>
+",
+ Regexp = "<TITLE>(.*)</TITLE>",
+ [{Name,Value}] = ts_search:parse_dynvar([{re, 'title', Regexp }],list_to_binary(Data)),
+ ?assertMatch("4DOM version 0.10.2", ts_search:subst("%%_title%%",[{Name,Value}])).
+
parse_extract_fun1_test() ->
myset_env(),
Data="/echo?symbol=%%ts_test_search:new%%",
View
@@ -263,13 +263,14 @@ parse_dynvar([],_Binary , _String,_Tree, DynVars) -> DynVars;
parse_dynvar(D=[{re,_, _}| _],Binary,undefined,Tree,DynVars) ->
parse_dynvar(D,Binary,Binary,Tree,DynVars);
parse_dynvar([{re,VarName, RegExp}| DynVarsSpecs],Binary,Data,Tree,DynVars) ->
- case re:run(Data, RegExp,[{capture,[2],list}]) of
+ case re:run(Data, RegExp,[{capture,[1],list}]) of
{match,[Value]} ->
- ?LOGF("DynVar: Match (~p=~p) ~n",[VarName, Value], ?DEB),
+ ?LOGF("DynVar (RE): Match (~p=~p) ~n",[VarName, Value], ?INFO),
parse_dynvar(DynVarsSpecs, Binary,Data,Tree,
ts_dynvars:set(VarName,Value,DynVars));
nomatch ->
- ?LOGF("Dyn Var: no Match (varname=~p), ~n",[VarName], ?WARN),
+ ?LOGF("Dyn Var (RE): no Match (varname=~p), ~n",[VarName], ?WARN),
+ ?LOGF("Regexp was: ~p ~n",[RegExp], ?INFO),
parse_dynvar(DynVarsSpecs, Binary,Data,Tree, ts_dynvars:set(VarName,"",DynVars))
end;
@@ -451,20 +451,23 @@ parse(#xmlElement{name=dyn_variable, attributes=Attrs},
StrName = ts_utils:clean_str(getAttr(Attrs, name)),
{ok, [{atom,1,Name}],1} = erl_scan:string("'"++StrName++"'"),
{Type,Expr} = case {getAttr(string,Attrs,regexp,none),
+ getAttr(string,Attrs,re,none),
getAttr(string,Attrs,pgsql_expr,none),
getAttr(string,Attrs,xpath,none),
getAttr(string,Attrs,jsonpath,none)} of
- {none,none,none,none} ->
+ {none,none,none,none,none} ->
DefaultRegExp = ?DEF_REGEXP_DYNVAR_BEGIN ++ StrName
++?DEF_REGEXP_DYNVAR_END,
{regexp,DefaultRegExp};
- {none,none,XPath,none} ->
+ {none,none,none,XPath,none} ->
{xpath,XPath};
- {none,none,none,JSONPath} ->
+ {none,none,none,none,JSONPath} ->
{jsonpath,JSONPath};
- {none,PG,none,none} ->
+ {none,none,PG,none,none} ->
{pgsql_expr,PG};
- {RegExp,_,_,_} ->
+ {none,RE,none,none,none} ->
+ {re,RE};
+ {RegExp,_,_,_,_} ->
{regexp,RegExp}
end,
FlattenExpr =lists:flatten(Expr),
@@ -477,7 +480,7 @@ parse(#xmlElement{name=dyn_variable, attributes=Attrs},
re ->
?LOGF("Add new re: ~s ~n", [Expr],?INFO),
{ok, CompiledRegExp} = re:compile(FlattenExpr),
- {regexp,Name,CompiledRegExp};
+ {re,Name,CompiledRegExp};
xpath ->
?LOGF("Add new xpath: ~s ~n", [Expr],?INFO),
CompiledXPathExp = mochiweb_xpath:compile_xpath(FlattenExpr),
@@ -562,8 +562,7 @@ decode_filename("ts_encoded" ++ String)->
lists:foldl(fun replace_str/2, String, Transform).
replace_str({A,B},X) ->
- {ok, Str, _} = re:gsub(X,A,B),
- Str.
+ re:replace(X,A,B,[{return,list},global]).
%%----------------------------------------------------------------------
%% Func: print_info/0 Print system info
@@ -758,7 +757,7 @@ set_remote_args(LogDir,PortsRange)->
{ok, PAList} = init:get_argument(pa),
PA = lists:flatmap(fun(A) -> [" -pa "] ++A end,PAList),
?DebugF("PA list ~p ~n", [PA]),
- {ok, Boot, _} = re:gsub(BootController,"tsung_controller","tsung"),
+ Boot = re:replace(BootController,"tsung_controller","tsung",[{return,list},global]),
?DebugF("Boot ~p~n", [Boot]),
Sys_Args= ts_utils:erl_system_args(),
LogDirEnc = encode_filename(LogDir),

0 comments on commit b6fac57

Please sign in to comment.