From 6aaeffe65aabb55bde718a7ad04b4347db553c46 Mon Sep 17 00:00:00 2001 From: Andrzej Jarmoniuk Date: Thu, 8 Sep 2022 06:48:53 +0200 Subject: [PATCH] MSHARED-1130: Sanitised value nullability in match(Pattern, boolean, String) --- .../filter/PatternIncludesArtifactFilter.java | 2 +- .../AbstractPatternArtifactFilterTest.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilter.java b/src/main/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilter.java index 3afbbde..274e885 100644 --- a/src/main/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilter.java +++ b/src/main/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilter.java @@ -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; diff --git a/src/test/java/org/apache/maven/shared/artifact/filter/AbstractPatternArtifactFilterTest.java b/src/test/java/org/apache/maven/shared/artifact/filter/AbstractPatternArtifactFilterTest.java index 2a6d914..3a92dec 100644 --- a/src/test/java/org/apache/maven/shared/artifact/filter/AbstractPatternArtifactFilterTest.java +++ b/src/test/java/org/apache/maven/shared/artifact/filter/AbstractPatternArtifactFilterTest.java @@ -579,4 +579,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.getType() ).thenReturn( null ); + + final ArtifactFilter filter = createFilter( + Collections.singletonList( "test-group:test-artifact:*:ERROR*" ) ); + + if ( isInclusionNotExpected() ) + { + assertTrue( filter.include( artifact ) ); + } + else + { + assertFalse( filter.include( artifact ) ); + } + } }