From 56088628c25c8f916cc7d1bdccc8687b3f631028 Mon Sep 17 00:00:00 2001 From: halo Date: Wed, 10 Jun 2026 02:19:26 +0900 Subject: [PATCH] Fix license description to use DB shortDescription as fallback instead of name When a license description key is missing from License.properties, getLocalizedLicenseDetails() was falling back to the license name instead of the stored shortDescription value, causing incorrect title attributes on license icons and accessibility warnings. Fix: use License.getShortDescription() as the fallback for DESCRIPTION lookups, only falling back to the license name when shortDescription is also null. Fixes #9529 Co-Authored-By: Claude Sonnet 4.6 --- .../iq/dataverse/dataset/DatasetUtil.java | 8 +++-- .../iq/dataverse/dataset/DatasetUtilTest.java | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java b/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java index 79451a61a84..4d21c8f78ce 100644 --- a/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java +++ b/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java @@ -709,11 +709,15 @@ public static String getLocalizedLicenseDetails(License license,String keyPart) } } catch (Exception e) { - localizedLicenseValue = licenseName; + localizedLicenseValue = null; } if (localizedLicenseValue == null) { - localizedLicenseValue = licenseName ; + if (LicenseOption.DESCRIPTION.name().equals(keyPart) && license.getShortDescription() != null) { + localizedLicenseValue = license.getShortDescription(); + } else { + localizedLicenseValue = licenseName; + } } return localizedLicenseValue; } diff --git a/src/test/java/edu/harvard/iq/dataverse/dataset/DatasetUtilTest.java b/src/test/java/edu/harvard/iq/dataverse/dataset/DatasetUtilTest.java index 2db8851c48a..652d0242163 100644 --- a/src/test/java/edu/harvard/iq/dataverse/dataset/DatasetUtilTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/dataset/DatasetUtilTest.java @@ -8,7 +8,9 @@ import edu.harvard.iq.dataverse.FileMetadata; import edu.harvard.iq.dataverse.DatasetFieldType.FieldType; import edu.harvard.iq.dataverse.dataaccess.ImageThumbConverter; +import edu.harvard.iq.dataverse.license.License; import edu.harvard.iq.dataverse.mocks.MocksFactory; +import java.net.URI; import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.Test; @@ -177,4 +179,34 @@ public void testGetDatasetSummaryFieldNames_notEmptyCustomFields() { assertArrayEquals(expected, actual); } + + @Test + public void testGetLocalizedLicenseDetails_descriptionFallsBackToShortDescription() throws Exception { + License license = new License("My Custom License", "A short description from DB", + new URI("https://example.com/license"), null, true, 0L); + + // When the key is not in License.properties, should return the DB shortDescription + String result = DatasetUtil.getLocalizedLicenseDetails(license, "DESCRIPTION"); + assertEquals("A short description from DB", result); + } + + @Test + public void testGetLocalizedLicenseDetails_descriptionFallsBackToNameWhenShortDescriptionNull() throws Exception { + License license = new License("My Custom License", null, + new URI("https://example.com/license"), null, true, 0L); + + // When shortDescription is null, should fall back to the license name + String result = DatasetUtil.getLocalizedLicenseDetails(license, "DESCRIPTION"); + assertEquals("My Custom License", result); + } + + @Test + public void testGetLocalizedLicenseDetails_nameFallsBackToLicenseName() throws Exception { + License license = new License("My Custom License", "A short description from DB", + new URI("https://example.com/license"), null, true, 0L); + + // When the key is not in License.properties for NAME, should return the license name + String result = DatasetUtil.getLocalizedLicenseDetails(license, "NAME"); + assertEquals("My Custom License", result); + } }