SensorStrategy sensorStrategy, @Nullable String oldRelativeFilePath) {
super(batchId);
this.projectKey = projectKey;
- this.projectRelativePath = PathUtils.sanitize(projectRelativePath);
+ this.projectRelativePath = checkSanitize(projectRelativePath);
this.moduleRelativePath = PathUtils.sanitize(moduleRelativePath);
this.type = type;
this.language = language;
validateKeyLength();
}
+ static String checkSanitize(String relativePath) {
+ String sanitized = PathUtils.sanitize(relativePath);
+ if(sanitized == null) {
+ throw new IllegalArgumentException(String.format("The path '%s' must sanitize to a non-null value", relativePath));
+ }
+ return sanitized;
+ }
+
private void validateKeyLength() {
String key = key();
if (key.length() > MAX_KEY_LENGTH) {
.isInstanceOf(IllegalStateException.class)
.hasMessageEndingWith("length (401) is longer than the maximum authorized (400)");
}
+
+ @Test
+ public void sanitize_shouldThrow_whenRelativePathIsInvalid() {
+ String invalidPath = "./../foo/bar";
+ Assertions.assertThatThrownBy(() -> DefaultIndexedFile.checkSanitize(invalidPath))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining(invalidPath);
+ }
}