Skip to content

Commit babdf76

Browse files
committed
Validate MLflow PURL name
Signed-off-by: Keshav Priyadarshi <[email protected]>
1 parent 3bb3c7c commit babdf76

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/main/java/com/github/packageurl/PackageURL.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ public PackageURL(final String purl) throws MalformedPackageURLException {
183183
// The 'remainder' should now consist of an optional namespace and the name
184184
index = remainder.lastIndexOf('/');
185185
if (index <= start) {
186-
this.name = validateName(this.type, StringUtil.percentDecode(remainder.substring(start)));
186+
this.name = validateName(this.type, StringUtil.percentDecode(remainder.substring(start)), this.qualifiers);
187187
this.namespace = null;
188188
} else {
189-
this.name = validateName(this.type, StringUtil.percentDecode(remainder.substring(index + 1)));
189+
this.name = validateName(this.type, StringUtil.percentDecode(remainder.substring(index + 1)), this.qualifiers);
190190
remainder = remainder.substring(0, index);
191191
this.namespace = validateNamespace(this.type, parsePath(remainder.substring(start), false));
192192
}
@@ -231,9 +231,9 @@ public PackageURL(
231231
throws MalformedPackageURLException {
232232
this.type = StringUtil.toLowerCase(validateType(requireNonNull(type, "type")));
233233
this.namespace = validateNamespace(this.type, namespace);
234-
this.name = validateName(this.type, requireNonNull(name, "name"));
235-
this.version = validateVersion(this.type, version);
236234
this.qualifiers = parseQualifiers(qualifiers);
235+
this.name = validateName(this.type, requireNonNull(name, "name"), this.qualifiers);
236+
this.version = validateVersion(this.type, version);
237237
this.subpath = validateSubpath(subpath);
238238
verifyTypeConstraints(this.type, this.namespace, this.name);
239239
}
@@ -394,7 +394,7 @@ private static void validateChars(String value, IntPredicate predicate, String c
394394
return retVal;
395395
}
396396

397-
private static String validateName(final String type, final String value) throws MalformedPackageURLException {
397+
private static String validateName(final String type, final String value, final Map<String,String> qualifiers) throws MalformedPackageURLException {
398398
if (value.isEmpty()) {
399399
throw new MalformedPackageURLException("The PackageURL name specified is invalid");
400400
}
@@ -412,6 +412,9 @@ private static String validateName(final String type, final String value) throws
412412
case StandardTypes.OCI:
413413
temp = StringUtil.toLowerCase(value);
414414
break;
415+
case StandardTypes.MLFLOW:
416+
temp = validateMlflowName(value, qualifiers);
417+
break;
415418
case StandardTypes.PUB:
416419
temp = StringUtil.toLowerCase(value).replaceAll("[^a-z0-9_]", "_");
417420
break;
@@ -425,6 +428,19 @@ private static String validateName(final String type, final String value) throws
425428
return temp;
426429
}
427430

431+
/*
432+
MLflow names are case-sensitive for Azure ML and must be kept as-is,
433+
for Databricks it is case insensitive and must be lowercased.
434+
*/
435+
private static String validateMlflowName(final String name, final Map<String,String> qualifiers){
436+
437+
String value = qualifiers.get("repository_url");
438+
if (value != null && value.toLowerCase().contains("databricks")) {
439+
return StringUtil.toLowerCase(name);
440+
}
441+
return name;
442+
}
443+
428444
private static @Nullable String validateVersion(final String type, final @Nullable String value) {
429445
if (value == null) {
430446
return null;

0 commit comments

Comments
 (0)