From 872906a09b9be45a6aa00136bd600862778e60ac Mon Sep 17 00:00:00 2001 From: Anatol Sialitski Date: Mon, 21 Oct 2024 13:35:40 +0200 Subject: [PATCH] Handle duplicate keys in map #10734 --- .../enonic/xp/portal/impl/url/RichTextProcessor.java | 3 ++- .../url/PortalUrlServiceImpl_processHtmlTest.java | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/portal/portal-impl/src/main/java/com/enonic/xp/portal/impl/url/RichTextProcessor.java b/modules/portal/portal-impl/src/main/java/com/enonic/xp/portal/impl/url/RichTextProcessor.java index b1697f1d2b2..e79bc27343a 100644 --- a/modules/portal/portal-impl/src/main/java/com/enonic/xp/portal/impl/url/RichTextProcessor.java +++ b/modules/portal/portal-impl/src/main/java/com/enonic/xp/portal/impl/url/RichTextProcessor.java @@ -308,7 +308,8 @@ private Map getImageStyleMap( final StyleDescriptors styleDe return styleDescriptors.stream() .flatMap( styleDescriptor -> styleDescriptor.getElements().stream() ) .filter( elementStyle -> ImageStyle.STYLE_ELEMENT_NAME.equals( elementStyle.getElement() ) ) - .collect( Collectors.toUnmodifiableMap( ElementStyle::getName, elementStyle -> (ImageStyle) elementStyle ) ); + .collect( Collectors.toUnmodifiableMap( ElementStyle::getName, elementStyle -> (ImageStyle) elementStyle, + ( existingKey, newKey ) -> existingKey ) ); } private StyleDescriptors getStyleDescriptors( final PortalRequest portalRequest ) diff --git a/modules/portal/portal-impl/src/test/java/com/enonic/xp/portal/impl/url/PortalUrlServiceImpl_processHtmlTest.java b/modules/portal/portal-impl/src/test/java/com/enonic/xp/portal/impl/url/PortalUrlServiceImpl_processHtmlTest.java index c765df163ed..533740c0e3d 100644 --- a/modules/portal/portal-impl/src/test/java/com/enonic/xp/portal/impl/url/PortalUrlServiceImpl_processHtmlTest.java +++ b/modules/portal/portal-impl/src/test/java/com/enonic/xp/portal/impl/url/PortalUrlServiceImpl_processHtmlTest.java @@ -340,12 +340,16 @@ public void process_image_with_styles() aspectRatio( "2:1" ). filter( "myfilter" ). build(); - final StyleDescriptor styleDescriptor = StyleDescriptor.create(). - application( ApplicationKey.from( "myapp" ) ). + final StyleDescriptor styleDescriptor1 = StyleDescriptor.create(). + application( ApplicationKey.from( "myapp1" ) ). addStyleElement( imageStyle ). build(); - when( styleDescriptorService.getByApplications( Mockito.any() ) ). - thenReturn( StyleDescriptors.from( styleDescriptor ) ); + final StyleDescriptor styleDescriptor2 = StyleDescriptor.create(). + application( ApplicationKey.from( "myapp2" ) ). + addStyleElement( imageStyle ). + build(); + when( styleDescriptorService.getByApplications( Mockito.any() ) ).thenReturn( + StyleDescriptors.from( styleDescriptor1, styleDescriptor2 ) ); final Map imageProjection = new HashMap<>();