Skip to content

Commit

Permalink
Fix normalize_expression to ignore predefined variables
Browse files Browse the repository at this point in the history
  • Loading branch information
marissa-masangcay authored and const-cloudinary committed Sep 10, 2019
1 parent b9dfb84 commit 45181e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Cloudinary.php
Expand Up @@ -944,8 +944,8 @@ private static function normalize_expression($exp)
return $exp;
} else {
if (empty(self::$IF_REPLACE_RE)) {
self::$IF_REPLACE_RE = '/((\|\||>=|<=|&&|!=|>|=|<|\/|\-|\+|\*|\^)(?=[ _])|'.
implode('|', array_keys(self::$PREDEFINED_VARS)) . ')/';
self::$IF_REPLACE_RE = '/((\|\||>=|<=|&&|!=|>|=|<|\/|\-|\+|\*|\^)(?=[ _])|(?<!\$)('.
implode('|', array_keys(self::$PREDEFINED_VARS)) . '))/';
}
if (isset($exp)) {
$exp = preg_replace('/[ _]+/', '_', $exp);
Expand Down
14 changes: 14 additions & 0 deletions tests/CloudinaryTest.php
Expand Up @@ -1538,6 +1538,20 @@ public function test_translate_if()
$this->assertEquals(array(), $options);
}

public function test_normalize_expression_should_not_convert_user_variables()
{
$options = array(
'transformation' => array(
array('$width' => 10),
array('width' => '$width + 10 + width'),
),
);

$t = Cloudinary::generate_transformation_string($options);

$this->assertEquals('$width_10/w_$width_add_10_add_w', $t);
}

public function test_array_should_define_set_of_variables()
{
$options = array(
Expand Down

0 comments on commit 45181e5

Please sign in to comment.