Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Replace all illegal chars in disk aliases #408

Merged
merged 3 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.ovirt.engine.core.common.job.StepEnum;
import org.ovirt.engine.core.common.queries.IdQueryParameters;
import org.ovirt.engine.core.common.queries.QueryType;
import org.ovirt.engine.core.common.utils.ValidationUtils;
import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
import org.ovirt.engine.core.common.vdscommands.VdsAndVmIDVDSParametersBase;
import org.ovirt.engine.core.compat.Guid;
Expand All @@ -75,6 +76,8 @@ public class ImportVmFromExternalProviderCommand<T extends ImportVmFromExternalP

private static final Pattern VMWARE_DISK_NAME_PATTERN = Pattern.compile("\\[.*?\\] .*/(.*).vmdk");
private static final Pattern DISK_NAME_PATTERN = Pattern.compile(".*/([^.]+).*");
private static final Pattern DISK_ALIAS_ILLEGAL_CHARS_PATTERN =
Pattern.compile("[^" + ValidationUtils.NO_SPECIAL_CHARACTER_CLASS_I18N + "]");

private static final String VDSM_COMPAT_VERSION_1_1 = "1.1";

Expand Down Expand Up @@ -369,7 +372,7 @@ && getStorageDomain().getStorageType().isBlockDomain()) {
}

private static String replaceInvalidDiskAliasChars(String alias) {
return alias.replace(' ', '_');
return DISK_ALIAS_ILLEGAL_CHARS_PATTERN.matcher(alias).replaceAll("_");
smelamud marked this conversation as resolved.
Show resolved Hide resolved
}

protected static String renameDiskAlias(OriginType originType, String alias) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ public void renameXenImage() {
String alias = ImportVmFromExternalProviderCommand.renameDiskAlias(OriginType.XEN, "/home/vdsm/Fedora22.img");
assertEquals("Fedora22", alias);
}

@Test
public void renameImageWithSpecialChars() {
String alias = ImportVmFromExternalProviderCommand.renameDiskAlias(OriginType.VMWARE, "[datastore] Fedora21/Fedora 21-yy%2fmm.vmdk");
assertEquals("Fedora_21-yy_2fmm", alias);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class ValidationUtils {

public static final String NO_SPECIAL_CHARACTERS_EXTRA_I18N = "^[\\p{L}0-9._\\+-]*$";
public static final String CUSTOM_CPU_NAME = "^[\\p{L}0-9._\\+\\-,]*$";
public static final String NO_SPECIAL_CHARACTERS_I18N = "^[\\p{L}0-9._-]*$";
public static final String NO_SPECIAL_CHARACTER_CLASS_I18N = "\\p{L}0-9._-";
public static final String NO_SPECIAL_CHARACTERS_I18N = "^["+ NO_SPECIAL_CHARACTER_CLASS_I18N + "]*$";
public static final String NO_SPECIAL_CHARACTERS = "[0-9a-zA-Z_-]+";
public static final String ONLY_I18N_ASCII_OR_NONE = "[\\p{ASCII}\\p{L}]*";
public static final String ONLY_ASCII_OR_NONE = "[\\p{ASCII}]*";
Expand Down