Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSHARED-1130] Sanitised value nullability in match(Pattern, boolean, String) #31

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ public boolean matches( Artifactoid artifactoid )
private static boolean match( final String pattern, final boolean containsAsterisk, final String value )
{
char[] patArr = pattern.toCharArray();
char[] strArr = value.toCharArray();
char[] strArr = value != null ? value.toCharArray() : new char[0];
int patIdxStart = 0;
int patIdxEnd = patArr.length - 1;
int strIdxStart = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@
* under the License.
*/

import static org.junit.Assert.assertFalse;
jarmoniak marked this conversation as resolved.
Show resolved Hide resolved
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public abstract class AbstractPatternArtifactFilterTest
{

Expand Down Expand Up @@ -579,4 +581,26 @@ public void testmassembly955()
assertTrue( filter.include( artifact2 ) );
}
}

@Test
public void testPartialWildcardShouldNotMatchEmptyComponent()
{
Artifact artifact = mock( Artifact.class );
when( artifact.getGroupId() ).thenReturn( "test-group" );
when( artifact.getArtifactId() ).thenReturn( "test-artifact" );
when( artifact.getVersion() ).thenReturn( "test-version" );
when( artifact.hasClassifier() ).thenReturn( false );

ArtifactFilter filter = createFilter(
Collections.singletonList( "test-group:test-artifact:*:ERROR*" ) );

if ( isInclusionNotExpected() )
{
assertTrue( filter.include( artifact ) );
}
else
{
assertFalse( filter.include( artifact ) );
}
}
}