Skip to content
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
2 changes: 2 additions & 0 deletions dap4/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ dependencies {

testImplementation(project(":cdm-test-utils"))

testImplementation(libs.google.truth)

testCompileOnly(libs.junit4)

testRuntimeOnly(libs.junit5.platformLauncher)
Expand Down
16 changes: 10 additions & 6 deletions dap4/src/main/java/dap4/core/dmr/DMRPrinter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012, UCAR/Unidata.
* See the LICENSE file for more information.
* Copyright (c) 2012-2025 University Corporation for Atmospheric Research/Unidata
* See LICENSE for license information.
*/

package dap4.core.dmr;
Expand Down Expand Up @@ -531,10 +531,14 @@ void printAttribute(DapAttribute attr) throws IOException {
printer.marginPrintln(cs);
}
} else {
for (int i = 0; i < svec.length; i++) {
String s = Escape.entityEscape(svec[i], null);
String cs = String.format("<Value value=\"%s\"/>", s);
printer.marginPrintln(cs);
if (svec.length == 0) {
printer.marginPrintln("<Value/>");
} else {
for (String string : svec) {
String s = Escape.entityEscape(string, null);
String cs = String.format("<Value value=\"%s\"/>", s);
printer.marginPrintln(cs);
}
}
}
printer.outdent();
Expand Down
28 changes: 28 additions & 0 deletions dap4/src/test/java/dap4/core/dmr/TestDMRPrinterEdgeCases.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2025 University Corporation for Atmospheric Research/Unidata
* See LICENSE for license information.
*/

package dap4.core.dmr;

import static com.google.common.truth.Truth.assertThat;

import dap4.core.util.IndentWriter;
import java.io.IOException;
import java.io.StringWriter;
import org.junit.Test;

public class TestDMRPrinterEdgeCases {
@Test
public void testNullValueAttr() throws IOException {
DapAttribute attr = new DapAttribute("name", DapType.STRING);
attr.setValues(new String[] {});
DMRPrinter dmrPrinter = new DMRPrinter();
StringWriter sw = new StringWriter();
dmrPrinter.printer = new IndentWriter(sw);
dmrPrinter.printAttribute(attr);
String encodedAttribute = sw.toString();
assertThat(encodedAttribute).isNotEmpty();
assertThat(encodedAttribute).ignoringCase().contains("<value/>");
}
}