Skip to content

Commit e670916

Browse files
committed
Fix single character variable
1 parent aaac4f3 commit e670916

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

cloudinary-core/src/main/java/com/cloudinary/utils/StringUtils.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,8 @@ public static String mergeToSingleUnderscore(String s) {
277277
*/
278278
public static boolean isVariable(String s) {
279279
if (s == null ||
280-
s.length() < 3 ||
281-
!s.startsWith("$") ||
282-
!Character.isLetter(s.charAt(1))) {
280+
s.length() < 2 ||
281+
!s.startsWith("$")) {
283282
return false;
284283
}
285284

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.cloudinary.transformation;
2+
3+
import com.cloudinary.Cloudinary;
4+
import com.cloudinary.Transformation;
5+
import org.junit.Before;
6+
import org.junit.Rule;
7+
import org.junit.Test;
8+
import org.junit.rules.TestName;
9+
10+
import static org.junit.Assert.assertEquals;
11+
12+
public class VariableTest {
13+
14+
private Cloudinary cloudinary;
15+
16+
@Rule
17+
public TestName currentTest = new TestName();
18+
19+
@Before
20+
public void setUp() {
21+
System.out.println("Running " + this.getClass().getName() + "." + currentTest.getMethodName());
22+
this.cloudinary = new Cloudinary("cloudinary://a:b@test123?load_strategies=false");
23+
}
24+
25+
@Test
26+
public void testSingleCharacterVariable() {
27+
String url = cloudinary.url().transformation(new Transformation().variable("$a","100").chain().height("$a")).generate("sample.jpg");
28+
assertEquals("http://res.cloudinary.com/test123/image/upload/$a_100/h_$a/sample.jpg", url);
29+
}
30+
31+
@Test
32+
public void testDollarOnlyAsVariable() {
33+
String url = cloudinary.url().transformation(new Transformation().variable("$","100").chain().height("$")).generate("sample.jpg");
34+
assertEquals("http://res.cloudinary.com/test123/image/upload/h_$/sample.jpg", url);
35+
}
36+
37+
@Test
38+
public void testMultipleCharactersVariable() {
39+
String url = cloudinary.url().transformation(new Transformation().variable("$a45","100").chain().height("$a45")).generate("sample.jpg");
40+
assertEquals("http://res.cloudinary.com/test123/image/upload/$a45_100/h_$a45/sample.jpg", url);
41+
}
42+
}

0 commit comments

Comments
 (0)