Skip to content

Commit 39bb5f9

Browse files
authored
Merge pull request #274 from jenkinsci/valid_id
Add underscores to the allowed set of characters for IDs.
2 parents c15cd21 + 55b0332 commit 39bb5f9

8 files changed

Lines changed: 14 additions & 14 deletions

File tree

pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
<commons.digester.version>2.1</commons.digester.version>
4242
<commons.digester3.version>3.2</commons.digester3.version>
4343
<commons.text.version>1.8</commons.text.version>
44-
<commons.validator.version>1.6</commons.validator.version>
4544
<eclipse-collections.version>9.2.0</eclipse-collections.version>
4645
<j2html.version>1.4.0</j2html.version>
4746

@@ -233,11 +232,6 @@
233232
<artifactId>commons-lang3</artifactId>
234233
<version>${commons.lang.version}</version>
235234
</dependency>
236-
<dependency>
237-
<groupId>commons-validator</groupId>
238-
<artifactId>commons-validator</artifactId>
239-
<version>${commons.validator.version}</version>
240-
</dependency>
241235
<dependency>
242236
<groupId>commons-io</groupId>
243237
<artifactId>commons-io</artifactId>

src/main/java/io/jenkins/plugins/analysis/core/util/ModelValidation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import java.nio.charset.IllegalCharsetNameException;
66
import java.nio.charset.UnsupportedCharsetException;
77
import java.util.Set;
8+
import java.util.regex.Pattern;
89

910
import org.apache.commons.lang3.StringUtils;
10-
import org.apache.commons.validator.routines.DomainValidator;
1111

1212
import edu.hm.hafner.analysis.Severity;
1313
import edu.hm.hafner.util.PathUtil;
@@ -28,8 +28,8 @@
2828
* @author Ullrich Hafner
2929
*/
3030
public class ModelValidation {
31-
/** All available character sets. */
3231
private static final Set<String> ALL_CHARSETS = Charset.availableCharsets().keySet();
32+
private static final Pattern VALID_ID_PATTERN = Pattern.compile("[a-z0-9][a-z0-9-_]*");
3333

3434
@VisibleForTesting
3535
static final String NO_REFERENCE_JOB = "-";
@@ -108,7 +108,7 @@ public FormValidation validateId(final String id) {
108108
}
109109

110110
private boolean isValidId(final String id) {
111-
return StringUtils.isEmpty(id) || DomainValidator.getInstance(true).isValid(id);
111+
return StringUtils.isEmpty(id) || VALID_ID_PATTERN.matcher(id).matches();
112112
}
113113

114114
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div>
22
The results of the selected tool are published using a unique ID (i.e. URL) which must not be already used by
33
another tool in this job. This ID is used as link to the results, so choose a short and meaningful name.
4+
Allowed elements are characters, digits, dashes and underscores (i.e., the ID must match `[a-z0-9][a-z0-9-_]*`).
45
If you leave the ID field empty, then the built-in default ID of the registered tool will be used.
56
</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div>
22
The results of the selected tool are published using a unique ID (i.e. URL) which must not be already used by
33
another tool in this job. This ID is used as link to the results, so choose a short and meaningful name.
4+
Allowed elements are characters, digits, dashes and underscores (i.e., the ID must match `[a-z0-9][a-z0-9-_]*`).
45
If you leave the ID field empty, then the built-in default ID of the registered tool will be used.
56
</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div>
22
The results of the selected tool are published using a unique ID (i.e. URL) which must not be already used by
33
another tool in this job. This ID is used as link to the results, so choose a short and meaningful name.
4+
Allowed elements are characters, digits, dashes and underscores (i.e., the ID must match `[a-z0-9][a-z0-9-_]*`).
45
If you leave the ID field empty, then the built-in default ID of the registered tool will be used.
56
</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div>
22
The results of the selected tool are published using a unique ID (i.e. URL) which must not be already used by
33
another tool in this job. This ID is used as link to the results, so choose a short and meaningful name.
4+
Allowed elements are characters, digits, dashes and underscores (i.e., the ID must match `[a-z0-9][a-z0-9-_]*`).
45
If you leave the ID field empty, then the built-in default ID of the registered tool will be used.
56
</div>

src/test/java/io/jenkins/plugins/analysis/core/model/LabelProviderFactoryITest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
import edu.hm.hafner.analysis.IssueParser;
1010
import edu.umd.cs.findbugs.annotations.NonNull;
11+
1112
import io.jenkins.plugins.analysis.core.model.LabelProviderFactory.StaticAnalysisToolFactory;
12-
import static io.jenkins.plugins.analysis.core.model.StaticAnalysisLabelProviderAssert.assertThat;
1313
import io.jenkins.plugins.analysis.core.testutil.IntegrationTestWithJenkinsPerSuite;
14+
15+
import static io.jenkins.plugins.analysis.core.model.StaticAnalysisLabelProviderAssert.*;
1416
import static org.mockito.Mockito.*;
1517

1618
/**
@@ -19,7 +21,7 @@
1921
* @author Ullrich Hafner
2022
*/
2123
public class LabelProviderFactoryITest extends IntegrationTestWithJenkinsPerSuite {
22-
private static final String ANNOTATED_ID = "annotatedTool";
24+
private static final String ANNOTATED_ID = "annotated-tool";
2325
private static final String PROVIDER_ID = "provider";
2426
private static final String UNDEFINED_ID = "undefined-id";
2527
private static final String TOOL_NAME = "Tool Name";
@@ -121,4 +123,4 @@ private Tool createTool(final String id) {
121123
}
122124

123125
}
124-
}
126+
}

src/test/java/io/jenkins/plugins/analysis/core/util/ModelValidationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
class ModelValidationTest {
3535
@ParameterizedTest(name = "{index} => Should be marked as illegal ID: \"{0}\"")
36-
@ValueSource(strings = {"a b", "a/b", "a#b"})
36+
@ValueSource(strings = {"a b", "a/b", "a#b", "äöü", "aö", "A", "aBc"})
3737
@DisplayName("should reject IDs")
3838
void shouldRejectId(final String id) {
3939
ModelValidation model = new ModelValidation();
@@ -43,7 +43,7 @@ void shouldRejectId(final String id) {
4343
}
4444

4545
@ParameterizedTest(name = "{index} => Should be marked as valid ID: \"{0}\"")
46-
@ValueSource(strings = {"", "a", "aWordb", "a-b"})
46+
@ValueSource(strings = {"", "a", "awordb", "a-b", "a_b", "", "0", "a0b", "12a34"})
4747
@DisplayName("should accept IDs")
4848
void shouldAcceptId(final String id) {
4949
ModelValidation model = new ModelValidation();

0 commit comments

Comments
 (0)