Skip to content

Commit f9d24ee

Browse files
authored
Fix properties not base64 decoded (#1565)
1 parent a481992 commit f9d24ee

18 files changed

+1649
-42
lines changed

src/CodeGenerator/src/Generator/ResponseParser/RestJsonParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,14 @@ private function parseResponseMap(MapShape $shape, string $input, bool $required
355355
$body = '
356356
$items = [];
357357
foreach ($json as $name => $value) {
358-
$items[(string) $name] = CLASS::create($value);
358+
$items[(string) $name] = BUILDER_CODE;
359359
}
360360
361361
return $items;
362362
';
363363

364364
$this->functions[$functionName] = $this->createPopulateMethod($functionName, strtr($body, [
365-
'CLASS' => $shape->getValue()->getShape()->getName(),
365+
'BUILDER_CODE' => $this->parseResponseStructure($shapeValue->getShape(), '$value', true),
366366
]), $shape);
367367
} else {
368368
$body = '

src/Service/DynamoDb/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## NOT RELEASED
44

5+
### BC-BREAK
6+
7+
- The value returned by `AttributeValue::getB` and `AttributeValue::getBS` is now base64 decoded.
8+
59
### Changed
610

711
- Allow passing explicit null values for optional fields of input objects

src/Service/DynamoDb/src/Exception/ConditionalCheckFailedException.php

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,97 @@ private function populateResultAttributeMap(array $json): array
4040
{
4141
$items = [];
4242
foreach ($json as $name => $value) {
43-
$items[(string) $name] = AttributeValue::create($value);
43+
$items[(string) $name] = $this->populateResultAttributeValue($value);
44+
}
45+
46+
return $items;
47+
}
48+
49+
private function populateResultAttributeValue(array $json): AttributeValue
50+
{
51+
return new AttributeValue([
52+
'S' => isset($json['S']) ? (string) $json['S'] : null,
53+
'N' => isset($json['N']) ? (string) $json['N'] : null,
54+
'B' => isset($json['B']) ? base64_decode((string) $json['B']) : null,
55+
'SS' => !isset($json['SS']) ? null : $this->populateResultStringSetAttributeValue($json['SS']),
56+
'NS' => !isset($json['NS']) ? null : $this->populateResultNumberSetAttributeValue($json['NS']),
57+
'BS' => !isset($json['BS']) ? null : $this->populateResultBinarySetAttributeValue($json['BS']),
58+
'M' => !isset($json['M']) ? null : $this->populateResultMapAttributeValue($json['M']),
59+
'L' => !isset($json['L']) ? null : $this->populateResultListAttributeValue($json['L']),
60+
'NULL' => isset($json['NULL']) ? filter_var($json['NULL'], \FILTER_VALIDATE_BOOLEAN) : null,
61+
'BOOL' => isset($json['BOOL']) ? filter_var($json['BOOL'], \FILTER_VALIDATE_BOOLEAN) : null,
62+
]);
63+
}
64+
65+
/**
66+
* @return string[]
67+
*/
68+
private function populateResultBinarySetAttributeValue(array $json): array
69+
{
70+
$items = [];
71+
foreach ($json as $item) {
72+
$a = isset($item) ? base64_decode((string) $item) : null;
73+
if (null !== $a) {
74+
$items[] = $a;
75+
}
76+
}
77+
78+
return $items;
79+
}
80+
81+
/**
82+
* @return AttributeValue[]
83+
*/
84+
private function populateResultListAttributeValue(array $json): array
85+
{
86+
$items = [];
87+
foreach ($json as $item) {
88+
$items[] = $this->populateResultAttributeValue($item);
89+
}
90+
91+
return $items;
92+
}
93+
94+
/**
95+
* @return array<string, AttributeValue>
96+
*/
97+
private function populateResultMapAttributeValue(array $json): array
98+
{
99+
$items = [];
100+
foreach ($json as $name => $value) {
101+
$items[(string) $name] = $this->populateResultAttributeValue($value);
102+
}
103+
104+
return $items;
105+
}
106+
107+
/**
108+
* @return string[]
109+
*/
110+
private function populateResultNumberSetAttributeValue(array $json): array
111+
{
112+
$items = [];
113+
foreach ($json as $item) {
114+
$a = isset($item) ? (string) $item : null;
115+
if (null !== $a) {
116+
$items[] = $a;
117+
}
118+
}
119+
120+
return $items;
121+
}
122+
123+
/**
124+
* @return string[]
125+
*/
126+
private function populateResultStringSetAttributeValue(array $json): array
127+
{
128+
$items = [];
129+
foreach ($json as $item) {
130+
$a = isset($item) ? (string) $item : null;
131+
if (null !== $a) {
132+
$items[] = $a;
133+
}
44134
}
45135

46136
return $items;

src/Service/DynamoDb/src/Exception/TransactionCanceledException.php

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,39 @@ private function populateResultAttributeMap(array $json): array
140140
{
141141
$items = [];
142142
foreach ($json as $name => $value) {
143-
$items[(string) $name] = AttributeValue::create($value);
143+
$items[(string) $name] = $this->populateResultAttributeValue($value);
144+
}
145+
146+
return $items;
147+
}
148+
149+
private function populateResultAttributeValue(array $json): AttributeValue
150+
{
151+
return new AttributeValue([
152+
'S' => isset($json['S']) ? (string) $json['S'] : null,
153+
'N' => isset($json['N']) ? (string) $json['N'] : null,
154+
'B' => isset($json['B']) ? base64_decode((string) $json['B']) : null,
155+
'SS' => !isset($json['SS']) ? null : $this->populateResultStringSetAttributeValue($json['SS']),
156+
'NS' => !isset($json['NS']) ? null : $this->populateResultNumberSetAttributeValue($json['NS']),
157+
'BS' => !isset($json['BS']) ? null : $this->populateResultBinarySetAttributeValue($json['BS']),
158+
'M' => !isset($json['M']) ? null : $this->populateResultMapAttributeValue($json['M']),
159+
'L' => !isset($json['L']) ? null : $this->populateResultListAttributeValue($json['L']),
160+
'NULL' => isset($json['NULL']) ? filter_var($json['NULL'], \FILTER_VALIDATE_BOOLEAN) : null,
161+
'BOOL' => isset($json['BOOL']) ? filter_var($json['BOOL'], \FILTER_VALIDATE_BOOLEAN) : null,
162+
]);
163+
}
164+
165+
/**
166+
* @return string[]
167+
*/
168+
private function populateResultBinarySetAttributeValue(array $json): array
169+
{
170+
$items = [];
171+
foreach ($json as $item) {
172+
$a = isset($item) ? base64_decode((string) $item) : null;
173+
if (null !== $a) {
174+
$items[] = $a;
175+
}
144176
}
145177

146178
return $items;
@@ -167,4 +199,62 @@ private function populateResultCancellationReasonList(array $json): array
167199

168200
return $items;
169201
}
202+
203+
/**
204+
* @return AttributeValue[]
205+
*/
206+
private function populateResultListAttributeValue(array $json): array
207+
{
208+
$items = [];
209+
foreach ($json as $item) {
210+
$items[] = $this->populateResultAttributeValue($item);
211+
}
212+
213+
return $items;
214+
}
215+
216+
/**
217+
* @return array<string, AttributeValue>
218+
*/
219+
private function populateResultMapAttributeValue(array $json): array
220+
{
221+
$items = [];
222+
foreach ($json as $name => $value) {
223+
$items[(string) $name] = $this->populateResultAttributeValue($value);
224+
}
225+
226+
return $items;
227+
}
228+
229+
/**
230+
* @return string[]
231+
*/
232+
private function populateResultNumberSetAttributeValue(array $json): array
233+
{
234+
$items = [];
235+
foreach ($json as $item) {
236+
$a = isset($item) ? (string) $item : null;
237+
if (null !== $a) {
238+
$items[] = $a;
239+
}
240+
}
241+
242+
return $items;
243+
}
244+
245+
/**
246+
* @return string[]
247+
*/
248+
private function populateResultStringSetAttributeValue(array $json): array
249+
{
250+
$items = [];
251+
foreach ($json as $item) {
252+
$a = isset($item) ? (string) $item : null;
253+
if (null !== $a) {
254+
$items[] = $a;
255+
}
256+
}
257+
258+
return $items;
259+
}
170260
}

0 commit comments

Comments
 (0)