Skip to content

Commit

Permalink
Merge pull request #302 from esmero/ISSUE-300
Browse files Browse the repository at this point in the history
ISSUE-300: 1.4.0 version of safer trim for Key Name Providers
  • Loading branch information
DiegoPino authored Feb 9, 2024
2 parents 12dbc38 + 51e0129 commit 3300fe6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
13 changes: 11 additions & 2 deletions src/Plugin/DataType/StrawberryValuesFromJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,21 @@ public function process($langcode = NULL)
// @TODO should we allow unicode directly?
$item = json_encode($item,JSON_UNESCAPED_UNICODE);
}
elseif (is_string($item)) {
$item = trim($item);
}
}
// This is an array, don't double nest to make the normalizer happy.
$values = array_map('trim', $flattened[$needle]);
$values = array_filter($flattened[$needle], function($value) {
// Only filter out nulls and empties. Keep FALSE/and 0
return ($value !== NULL && $value !== '');
});
}
elseif (isset($flattened[$needle])) {
$values[] = trim($flattened[$needle]);
$flattened[$needle] = is_string($flattened[$needle]) ? trim($flattened[$needle]) : $flattened[$needle];
if ($flattened[$needle] !== '') {
$values[] = $flattened[$needle];
}
}
$this->processed = array_values($values);
$this->list = [];
Expand Down
19 changes: 13 additions & 6 deletions src/Plugin/DataType/StrawberryValuesViaJmesPathFromJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public function process($langcode = NULL)
// We could also just get the first order values?
// @TODO, ask the team.
$jmespath_result_to_expose[] = json_encode($item, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
} else {
}
else {
$jmespath_result_to_expose = array_merge($jmespath_result_to_expose, $item);
}
}
Expand All @@ -84,13 +85,18 @@ public function process($langcode = NULL)
}
}
// This is an array, don't double nest to make the normalizer happy.
$jmespath_result_to_expose = array_filter($jmespath_result_to_expose);
foreach($jmespath_result_to_expose as $i => $v) {
foreach($jmespath_result_to_expose as $i => &$v) {
if(is_array($v) or is_object($v)) {
$jmespath_result_to_expose[$i] = json_encode($v);
$v = json_encode($v);
}
elseif (is_string($v)) {
$v = trim($v);
}
}
$values = array_map('trim', $jmespath_result_to_expose);
$values = array_filter($jmespath_result_to_expose, function($value) {
// Only filter out nulls and empties. Keep FALSE/and 0
return ($value !== NULL && $value !== '');
});
$values = array_map('stripslashes', $values);
if ($is_date) {
$values_parsed = [];
Expand Down Expand Up @@ -132,8 +138,9 @@ public function process($langcode = NULL)
}
}
$values = array_unique($values_parsed);
$values = array_filter(array_values($values));
}
$this->processed = array_filter(array_values($values));
$this->processed = array_values($values);
$this->list = [];
foreach ($this->processed as $delta => $item) {
$this->list[$delta] = $this->createItem($delta, $item);
Expand Down

0 comments on commit 3300fe6

Please sign in to comment.