2020-07-11 03:27:35 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								%% This Source Code Form is subject to the terms of the Mozilla Public
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								%% License, v. 2.0. If a copy of the MPL was not distributed with this
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								%%
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-10 23:05:48 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								%% Copyright (c) 2007-2020 VMware, Inc. or its affiliates.  All rights reserved.
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								%%
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								-module(wildcard_match_SUITE).
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								-compile(export_all).
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								-include_lib("eunit/include/eunit.hrl").
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								all() ->
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        exact_match,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        prefix_match,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        suffix_match,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        mixed_match
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ].
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								exact_match(_Config) ->
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"value">>, <<"value">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"string with / special % characters">>,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                      <<"string%20with%20%2F%20special%20%25%20characters">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"pattern with  plus  spaces">>,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                          <<"pattern+with++plus++spaces">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"pattern with plus spaces and * wildcard encoded">>,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                          <<"pattern+with+plus+spaces+and+%2A+wildcard+encoded">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"case with * special / characters">>,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                          <<"case+with+%2a+special+%2f+characters">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(false, wildcard:match(<<"casesensitive">>, <<"CaseSensitive">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(false, wildcard:match(<<"foo">>, <<"fo">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(false, wildcard:match(<<"foo">>, <<"fooo">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    %% Special characters and spaces should be %-encoded.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(false, wildcard:match(<<"string with unescaped % character">>,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                       <<"string with unescaped % character">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-12 05:20:09 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    %% Here a wildcard is matched by another wildcard, so to match exactly the '*' character
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    %% we need to %-encode it
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"wildcard * is matched by wildcard">>,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                      <<"wildcard * is matched by wildcard">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"wildcard * and anything else is matched by wildcard">>,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                      <<"wildcard * is matched by wildcard">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"wildcard * is matched by urlencoded">>,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                      <<"wildcard+%2a+is+matched+by+urlencoded">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(false, wildcard:match(<<"wildcard * and extra content is not matched by urlencoded">>,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                       <<"wildcard+%2a+is+not+matched+by+urlencoded">>)),
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    %% Spaces do not interfere with parsing
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"pattern with  spaces">>,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                          <<"pattern with  spaces">>)).
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								suffix_match(_Config) ->
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"foo">>, <<"*oo">>)),
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    %% Empty prefix
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"foo">>, <<"*foo">>)),
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    %% Anything goes
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"foo">>, <<"*">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"line * with * special * characters">>, <<"*+characters">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"line * with * special * characters">>, <<"*special+%2A+characters">>)),
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(false, wildcard:match(<<"foo">>, <<"*r">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(false, wildcard:match(<<"foo">>, <<"*foobar">>)).
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								prefix_match(_Config) ->
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"foo">>, <<"fo*">>)),
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    %% Empty suffix
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"foo">>, <<"foo*">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"line * with * special * characters">>, <<"line+*">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"line * with * special * characters">>, <<"line+%2a*">>)),
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    %% Wildcard matches '*' character
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"string with unescaped *">>,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                           <<"string+with+unescaped+*">>)),
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(false, wildcard:match(<<"foo">>, <<"b*">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(false, wildcard:match(<<"foo">>, <<"barfoo*">>)).
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								mixed_match(_Config) ->
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    %% Empty wildcards
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"string">>, <<"*str*ing*">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"str*ing">>, <<"*str*ing*">>)),
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"some long string">>, <<"some*string">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"some long string">>, <<"some*long*string">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"some long string">>, <<"*some*string*">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"some long string">>, <<"*long*">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    %% Matches two spaces (3 or more words)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"some long string">>, <<"*+*+*">>)),
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(false, wildcard:match(<<"some string">>, <<"*+*+*">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(false, wildcard:match(<<"some long string">>, <<"some*other*string">>)),
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(true, wildcard:match(<<"some long string">>, <<"s*e*str*">>)),
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-27 06:39:25 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    %% The z doesn't appear in the subject
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(false, wildcard:match(<<"some long string">>, <<"s*z*str*">>)),
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-20 21:13:18 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-03 22:55:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(false, wildcard:match(<<"string">>, <<"*some*">>)),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ?assertEqual(false, wildcard:match(<<"string">>, <<"*some*string*">>)).
							 |