Xenserver smoke-test: Allow emojis to be accepted in volume name during volume creation (#10774)

* Allow emojis to be accepted in volume name during volume creation

* escape only non-ASCII characters
This commit is contained in:
Pearl Dsilva 2025-04-29 11:43:07 +05:30 committed by GitHub
parent 9f229600e6
commit 0e0ae226bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import static com.cloud.utils.ReflectUtil.flattenProperties;
import static com.google.common.collect.Lists.newArrayList;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
@ -810,7 +811,7 @@ public class XenServerStorageProcessor implements StorageProcessor {
final SR poolSr = hypervisorResource.getStorageRepository(conn,
CitrixHelper.getSRNameLabel(primaryStore.getUuid(), primaryStore.getPoolType(), primaryStore.getPath()));
VDI.Record vdir = new VDI.Record();
vdir.nameLabel = volume.getName();
vdir.nameLabel = getEncodedVolumeName(volume.getName());
vdir.SR = poolSr;
vdir.type = Types.VdiType.USER;
@ -831,6 +832,26 @@ public class XenServerStorageProcessor implements StorageProcessor {
}
}
private String getEncodedVolumeName(String volumeName) throws UnsupportedEncodingException {
byte[] utf8Bytes = volumeName.getBytes("UTF-8");
// Decode UTF-8 into a Java String (UTF-16)
String decoded = new String(utf8Bytes, "UTF-8");
// Print each code unit as a Unicode escape
StringBuilder unicodeEscaped = new StringBuilder();
for (int i = 0; i < decoded.length(); i++) {
char ch = decoded.charAt(i);
if (ch <= 127 && Character.isLetterOrDigit(ch)) {
// Keep ASCII alphanumerics as-is
unicodeEscaped.append(ch);
} else {
// Escape non-ASCII characters
unicodeEscaped.append(String.format("\\u%04X", (int) ch));
}
}
return unicodeEscaped.toString();
}
@Override
public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();