Skip to content

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

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

Merged
merged 3 commits into from
Apr 29, 2025
Merged
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 @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -810,7 +811,7 @@
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());

Check warning on line 814 in plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java#L814

Added line #L814 was not covered by tests
vdir.SR = poolSr;
vdir.type = Types.VdiType.USER;

Expand All @@ -831,6 +832,26 @@
}
}

private String getEncodedVolumeName(String volumeName) throws UnsupportedEncodingException {
byte[] utf8Bytes = volumeName.getBytes("UTF-8");

Check warning on line 836 in plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java#L835-L836

Added lines #L835 - L836 were not covered by tests
// Decode UTF-8 into a Java String (UTF-16)
String decoded = new String(utf8Bytes, "UTF-8");

Check warning on line 838 in plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java#L838

Added line #L838 was not covered by tests
// Print each code unit as a Unicode escape
StringBuilder unicodeEscaped = new StringBuilder();

Check warning on line 840 in plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java#L840

Added line #L840 was not covered by tests
for (int i = 0; i < decoded.length(); i++) {
char ch = decoded.charAt(i);

Check warning on line 842 in plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java#L842

Added line #L842 was not covered by tests
if (ch <= 127 && Character.isLetterOrDigit(ch)) {
// Keep ASCII alphanumerics as-is
unicodeEscaped.append(ch);

Check warning on line 845 in plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java#L845

Added line #L845 was not covered by tests
} else {
// Escape non-ASCII characters
unicodeEscaped.append(String.format("\\u%04X", (int) ch));

Check warning on line 848 in plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java#L848

Added line #L848 was not covered by tests
}
}

return unicodeEscaped.toString();
}

Check warning on line 853 in plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java#L852-L853

Added lines #L852 - L853 were not covered by tests

@Override
public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
Expand Down
Loading