-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### Proposed Changes * Added a utility method to check for vector image extensions in `UtilMethods`. * Updated `ImageFilterExporter` to skip transformation for vector images (SVG, EPS, etc.). ### Checklist - [x] Tests - [x] Translations - [x] Security Implications Contemplated (add notes if applicable) ### Additional Info This pull request addresses issue #30196, ensuring that the Image API ignores vector images during processing. Now only raster images will be transformed. ### Videos #### Original https://github.com/user-attachments/assets/8e6f04f7-aad9-4d20-a92b-b9e5c7bac485 #### Updated https://github.com/user-attachments/assets/bb2408f0-3db5-47f4-9dd2-85ba21e98bd0
- Loading branch information
1 parent
5738ed5
commit 0028f3c
Showing
5 changed files
with
1,729 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
.../java/com/dotmarketing/portlets/contentlet/business/exporter/ImageFilterExporterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package com.dotmarketing.portlets.contentlet.business.exporter; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import com.dotmarketing.portlets.contentlet.business.BinaryContentExporter.BinaryContentExporterData; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Unit tests for the ImageFilterExporter class. | ||
*/ | ||
class ImageFilterExporterTest { | ||
|
||
private ImageFilterExporter exporter; | ||
|
||
/** | ||
* Set up the ImageFilterExporter instance before each test. | ||
*/ | ||
@BeforeEach | ||
public void setUp() { | ||
exporter = new ImageFilterExporter(); | ||
} | ||
|
||
/** | ||
* Given a valid SVG image file and a set of parameters, | ||
* When exporting the content of the image, | ||
* Then the method should return a result without modifying the image. | ||
* | ||
* @throws Exception if an error occurs during export. | ||
*/ | ||
@Test | ||
void testExportContentWithSvgImage() throws Exception { | ||
// Given | ||
final URL url = getClass().getResource("/images/test.svg"); | ||
File inputFile = new File(Objects.requireNonNull(url).getFile()); | ||
Map<String, String[]> parameters = getSampleParameters(); | ||
|
||
// When | ||
BinaryContentExporterData result = exporter.exportContent(inputFile, parameters); | ||
|
||
// Then | ||
assertNotNull(result); | ||
assertTrue(FileUtils.contentEquals(inputFile, result.getDataFile())); // The file should not be transformed | ||
} | ||
|
||
/** | ||
* Given a valid EPS image file and a set of parameters, | ||
* When exporting the content of the image, | ||
* Then the method should return a result without modifying the image. | ||
* | ||
* @throws Exception if an error occurs during export. | ||
*/ | ||
@Test | ||
void testExportContentWithEpsImage() throws Exception { | ||
// Given | ||
final URL url = getClass().getResource("/images/test.eps"); | ||
final File inputFile = new File(Objects.requireNonNull(url).getFile()); | ||
Map<String, String[]> parameters = getSampleParameters(); | ||
|
||
// When | ||
final BinaryContentExporterData result = exporter.exportContent(inputFile, parameters); | ||
|
||
// Then | ||
assertNotNull(result); | ||
assertTrue(FileUtils.contentEquals(inputFile, result.getDataFile())); // The file should not be transformed | ||
} | ||
|
||
/** | ||
* Given a valid non-vector image file (JPG) and a set of parameters, | ||
* When exporting the content of the image, | ||
* Then the method should return a result with the image transformed. | ||
* | ||
* @throws Exception if an error occurs during export. | ||
*/ | ||
@Test | ||
void testExportContentWithNonVectorImage() throws Exception { | ||
// Given | ||
final URL url = getClass().getResource("/images/test.jpg"); | ||
final File inputFile = new File(Objects.requireNonNull(url).getFile()); | ||
Map<String, String[]> parameters = getSampleParameters(); | ||
|
||
// When | ||
final BinaryContentExporterData result = exporter.exportContent(inputFile, parameters); | ||
|
||
// Then | ||
assertNotNull(result); | ||
assertFalse(FileUtils.contentEquals(inputFile, result.getDataFile())); // The file should be transformed | ||
} | ||
|
||
/** | ||
* Helper method to provide a sample parameters map for use in the exportContent tests. | ||
* | ||
* @return a Map containing sample parameters. | ||
*/ | ||
final Map<String, String[]> getSampleParameters() { | ||
Map<String, String[]> parameters = new HashMap<>(); | ||
parameters.put("contentAsset", new String[]{"image"}); | ||
parameters.put("r", new String[]{"1728068872149"}); | ||
parameters.put("e5150266-7e28-445b-b5dd-193dc38922c7", new String[]{"asset"}); | ||
parameters.put("byInode", new String[]{"true"}); | ||
parameters.put("resize_w", new String[]{"500"}); | ||
parameters.put("quality_q", new String[]{"50"}); | ||
parameters.put("webp_q", new String[]{"50"}); | ||
parameters.put("fieldVarName", new String[]{"asset"}); | ||
parameters.put("assetInodeOrIdentifier", new String[]{"e5150266-7e28-445b-b5dd-193dc38922c7"}); | ||
return parameters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.