Skip to content

Commit 827ea3d

Browse files
author
RTLcoil
authored
Fix normalize_expression when a keyword is used in a variable name (#205)
1 parent bd0ff6f commit 827ea3d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

cloudinary-core/src/main/java/com/cloudinary/transformation/BaseExpression.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private static Pattern getPattern() {
107107
sb.append(Pattern.quote(op)).append("|");
108108
}
109109
sb.deleteCharAt(sb.length() - 1);
110-
sb.append(")(?=[ _])|").append(StringUtils.join(PREDEFINED_VARS.keySet(), "|")).append(")");
110+
sb.append(")(?=[ _])|(?<!\\$)(").append(StringUtils.join(PREDEFINED_VARS.keySet(), "|")).append("))");
111111
pattern = sb.toString();
112112
return Pattern.compile(pattern);
113113
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,14 @@ public void testShouldSupportPowOperator() {
218218

219219
assertEquals("$small_150,$big_$small_pow_1.5", t.generate());
220220
}
221+
222+
@Test
223+
public void testShouldNotChangeVariableNamesWhenTheyNamedAfterKeyword() {
224+
Transformation t = new Transformation()
225+
.variable("$width", 10)
226+
.chain()
227+
.width("$width + 10 + width");
228+
229+
assertEquals("$width_10/w_$width_add_10_add_w", t.generate());
230+
}
221231
}

0 commit comments

Comments
 (0)