Skip to content

Commit

Permalink
Merge pull request #274 from jenkinsci/valid_id
Browse files Browse the repository at this point in the history
Add underscores to the allowed set of characters for IDs.
  • Loading branch information
uhafner authored Nov 19, 2019
2 parents c15cd21 + 55b0332 commit 39bb5f9
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<commons.digester.version>2.1</commons.digester.version>
<commons.digester3.version>3.2</commons.digester3.version>
<commons.text.version>1.8</commons.text.version>
<commons.validator.version>1.6</commons.validator.version>
<eclipse-collections.version>9.2.0</eclipse-collections.version>
<j2html.version>1.4.0</j2html.version>

Expand Down Expand Up @@ -233,11 +232,6 @@
<artifactId>commons-lang3</artifactId>
<version>${commons.lang.version}</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>${commons.validator.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.util.Set;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.validator.routines.DomainValidator;

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

@VisibleForTesting
static final String NO_REFERENCE_JOB = "-";
Expand Down Expand Up @@ -108,7 +108,7 @@ public FormValidation validateId(final String id) {
}

private boolean isValidId(final String id) {
return StringUtils.isEmpty(id) || DomainValidator.getInstance(true).isValid(id);
return StringUtils.isEmpty(id) || VALID_ID_PATTERN.matcher(id).matches();
}

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

import edu.hm.hafner.analysis.IssueParser;
import edu.umd.cs.findbugs.annotations.NonNull;

import io.jenkins.plugins.analysis.core.model.LabelProviderFactory.StaticAnalysisToolFactory;
import static io.jenkins.plugins.analysis.core.model.StaticAnalysisLabelProviderAssert.assertThat;
import io.jenkins.plugins.analysis.core.testutil.IntegrationTestWithJenkinsPerSuite;

import static io.jenkins.plugins.analysis.core.model.StaticAnalysisLabelProviderAssert.*;
import static org.mockito.Mockito.*;

/**
Expand All @@ -19,7 +21,7 @@
* @author Ullrich Hafner
*/
public class LabelProviderFactoryITest extends IntegrationTestWithJenkinsPerSuite {
private static final String ANNOTATED_ID = "annotatedTool";
private static final String ANNOTATED_ID = "annotated-tool";
private static final String PROVIDER_ID = "provider";
private static final String UNDEFINED_ID = "undefined-id";
private static final String TOOL_NAME = "Tool Name";
Expand Down Expand Up @@ -121,4 +123,4 @@ private Tool createTool(final String id) {
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
class ModelValidationTest {
@ParameterizedTest(name = "{index} => Should be marked as illegal ID: \"{0}\"")
@ValueSource(strings = {"a b", "a/b", "a#b"})
@ValueSource(strings = {"a b", "a/b", "a#b", "äöü", "aö", "A", "aBc"})
@DisplayName("should reject IDs")
void shouldRejectId(final String id) {
ModelValidation model = new ModelValidation();
Expand All @@ -43,7 +43,7 @@ void shouldRejectId(final String id) {
}

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

0 comments on commit 39bb5f9

Please sign in to comment.