Uploaded image for project: 'Magnolia Standard Templating Kit (closed)'
  1. Magnolia Standard Templating Kit (closed)
  2. MGNLSTK-1274

Colon in image filename breaks getAssetVariation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Major Major
    • None
    • 2.0.12
    • templates
    • Yes

      When trying to resolve an asset variation for an uploaded image containing a colon ( : ) in the fileName, the link property in the result is null making it impossible to show the image.

      Underlying problem is that in the ImageOperationProvidingVariation is trying to put the (user created) fileName blindly in the java URI() class constructor causing a URISyntaxException and returning null from the createLink method.

      See the following commit:

      http://git.magnolia-cms.com/gitweb/?p=modules/standard-templating-kit.git;a=commitdiff;h=b8a611ff4e5301e3c02d9e9c6609827958c173c1

      This is a regression from Magnolia 4.4 to 4.5

      In the template we are using the following code to retrieve the link:

      stkfn.getAssetVariation(image, imageVariation).link

      JUnit testcase:

          @Test
          public void testCreateLinkWithInvalidURIChars(){
              // GIVEN
              Site site = mock(Site.class);
              final ThemeReference themeRef = new ThemeReference();
              themeRef.setName("myTheme");
              when(site.getTheme()).thenReturn(themeRef);
      
              Provider<Site> siteProvider = mock(Provider.class);
              when(siteProvider.get()).thenReturn(site);
      
              ImageOperationProvidingVariation imageOperationProvidingVariation = new ImageOperationProvidingVariation(siteProvider);
              imageOperationProvidingVariation.setGeneratorName("generatorName");
              imageOperationProvidingVariation.setName("name");
      
              imageNode.setProperty(FileProperties.PROPERTY_FILENAME, "name with : and ยง");
              
              // WHEN
              String link = imageOperationProvidingVariation.createLink(imageProperty);
      
              // THEN
              assertEquals("http://localhost:9090/demoAuthor/.imaging/generatorName/myTheme/name/website/image/name%20with%20%3A%20and%20%C2%A7.jpg", link);
          }
      

        Acceptance criteria

              czimmermann Christopher Zimmermann
              davidpronk David Pronk
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: