Skip to content

Commit 97e47c1

Browse files
authored
Support start offset and end offset in variable materialization
1 parent 65fd1e3 commit 97e47c1

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

cloudinary-core/src/main/java/com/cloudinary/Transformation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ public String generate(Map options) {
785785
}
786786
if (!components.isEmpty()) {
787787
final String joined = StringUtils.join(components, ",");
788-
transformations.add(Expression.normalize(joined));
788+
transformations.add(joined);
789789
}
790790

791791
if (isResponsive) {
@@ -894,7 +894,7 @@ private static String normRangeValue(Object objectValue) {
894894
Matcher matcher = RANGE_VALUE_RE.matcher(value);
895895

896896
if (!matcher.matches()) {
897-
return null;
897+
return Expression.normalize(value);
898898
}
899899

900900
String modifier = "";

cloudinary-core/src/test/java/com/cloudinary/TransformationTest.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
import com.cloudinary.transformation.TextLayer;
55
import com.cloudinary.utils.ObjectUtils;
66
import org.cloudinary.json.JSONArray;
7+
import org.hamcrest.CoreMatchers;
78
import org.junit.After;
89
import org.junit.Before;
910
import org.junit.Test;
11+
import org.junit.runner.RunWith;
12+
13+
import junitparams.JUnitParamsRunner;
14+
import junitparams.Parameters;
1015

1116
import java.util.*;
1217

@@ -18,6 +23,7 @@
1823
*
1924
*/
2025
@SuppressWarnings("unchecked")
26+
@RunWith(JUnitParamsRunner.class)
2127
public class TransformationTest {
2228

2329
@Before
@@ -300,4 +306,67 @@ public void testContextMetadataToUserVariables() {
300306

301307
assertEquals("$xpos_ctx:!x_pos!_to_f,$ypos_ctx:!y_pos!_to_f,c_crop,x_$xpos_mul_w,y_$ypos_mul_h", t.generate());
302308
}
309+
310+
@Parameters({ "angle",
311+
"aspect_ratio",
312+
"dpr",
313+
"effect",
314+
"height",
315+
"opacity",
316+
"quality",
317+
"width",
318+
"x",
319+
"y",
320+
"end_offset",
321+
"start_offset",
322+
"zoom" })
323+
@Test
324+
public void testVerifyNormalizationShouldNormalize(String input) throws Exception {
325+
String t = new Transformation().param(input, "width * 2").generate();
326+
assertThat(t, CoreMatchers.containsString("w_mul_2"));
327+
}
328+
329+
@Parameters({
330+
"audio_codec",
331+
"audio_frequency",
332+
"border",
333+
"bit_rate",
334+
"color_space",
335+
"default_image",
336+
"delay",
337+
"density",
338+
"fetch_format",
339+
"custom_function",
340+
"fps",
341+
"gravity",
342+
"overlay",
343+
"prefix",
344+
"page",
345+
"underlay",
346+
"video_sampling",
347+
"streaming_profile",
348+
"keyframe_interval"})
349+
@Test
350+
public void test1VerifyNormalizationShouldNotNormalize(String input) throws Exception {
351+
String t = new Transformation().param(input, "width * 2").generate();
352+
assertThat(t, CoreMatchers.not(CoreMatchers.containsString("w_mul_2")));
353+
}
354+
355+
@Test
356+
public void testSupportStartOffset() throws Exception {
357+
String t = new Transformation().width(100).startOffset("idu - 5").generate();
358+
assertThat(t, CoreMatchers.containsString("so_idu_sub_5"));
359+
360+
t = new Transformation().width(100).startOffset("$logotime").generate();
361+
assertThat(t, CoreMatchers.containsString("so_$logotime"));
362+
}
363+
364+
@Test
365+
public void testSupportEndOffset() throws Exception {
366+
String t = new Transformation().width(100).endOffset("idu - 5").generate();
367+
assertThat(t, CoreMatchers.containsString("eo_idu_sub_5"));
368+
369+
t = new Transformation().width(100).endOffset("$logotime").generate();
370+
assertThat(t, CoreMatchers.containsString("eo_$logotime"));
371+
}
303372
}

0 commit comments

Comments
 (0)