File tree Expand file tree Collapse file tree 3 files changed +40
-6
lines changed
Expand file tree Collapse file tree 3 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ dependencies {
2222
2323 testImplementation(project(" :cdm-test-utils" ))
2424
25+ testImplementation(libs.google.truth)
26+
2527 testCompileOnly(libs.junit4)
2628
2729 testRuntimeOnly(libs.junit5.platformLauncher)
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2012, UCAR /Unidata.
3- * See the LICENSE file for more information.
2+ * Copyright (c) 2012-2025 University Corporation for Atmospheric Research /Unidata
3+ * See LICENSE for license information.
44 */
55
66package dap4 .core .dmr ;
@@ -531,10 +531,14 @@ void printAttribute(DapAttribute attr) throws IOException {
531531 printer .marginPrintln (cs );
532532 }
533533 } else {
534- for (int i = 0 ; i < svec .length ; i ++) {
535- String s = Escape .entityEscape (svec [i ], null );
536- String cs = String .format ("<Value value=\" %s\" />" , s );
537- printer .marginPrintln (cs );
534+ if (svec .length == 0 ) {
535+ printer .marginPrintln ("<Value/>" );
536+ } else {
537+ for (String string : svec ) {
538+ String s = Escape .entityEscape (string , null );
539+ String cs = String .format ("<Value value=\" %s\" />" , s );
540+ printer .marginPrintln (cs );
541+ }
538542 }
539543 }
540544 printer .outdent ();
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2025 University Corporation for Atmospheric Research/Unidata
3+ * See LICENSE for license information.
4+ */
5+
6+ package dap4 .core .dmr ;
7+
8+ import static com .google .common .truth .Truth .assertThat ;
9+
10+ import dap4 .core .util .IndentWriter ;
11+ import java .io .IOException ;
12+ import java .io .StringWriter ;
13+ import org .junit .Test ;
14+
15+ public class TestDMRPrinterEdgeCases {
16+ @ Test
17+ public void testNullValueAttr () throws IOException {
18+ DapAttribute attr = new DapAttribute ("name" , DapType .STRING );
19+ attr .setValues (new String [] {});
20+ DMRPrinter dmrPrinter = new DMRPrinter ();
21+ StringWriter sw = new StringWriter ();
22+ dmrPrinter .printer = new IndentWriter (sw );
23+ dmrPrinter .printAttribute (attr );
24+ String encodedAttribute = sw .toString ();
25+ assertThat (encodedAttribute ).isNotEmpty ();
26+ assertThat (encodedAttribute ).ignoringCase ().contains ("<value />" );
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments