Skip to content

Commit 04dad05

Browse files
authored
Merge pull request #254 from ReCodEx/robust-localization
Making API more robust when some part of the localized text is not pr…
2 parents 084a7ee + 06e9f22 commit 04dad05

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

app/V1Module/presenters/AssignmentsPresenter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,18 @@ public function actionUpdateDetail(string $id) {
265265
throw new InvalidArgumentException("External assignment link is not a valid URL");
266266
}
267267

268-
$localized = new LocalizedExercise(
269-
$lang, $localization["name"], $localization["text"],
268+
$localizedTexts[$lang] = new LocalizedExercise(
269+
$lang,
270+
trim(Arrays::get($localization, "name", "")),
271+
trim(Arrays::get($localization, "text", "")),
270272
$localizedExercise ? $localizedExercise->getDescription() : "",
271273
$externalAssignmentLink ?: null
272274
);
273275

274-
$localizedTexts[$lang] = $localized;
275-
276276
if (array_key_exists("studentHint", $localization)) {
277277
$localizedAssignments[$lang] = new LocalizedAssignment(
278278
$lang,
279-
$localization["studentHint"]
279+
trim(Arrays::get($localization, "studentHint", ""))
280280
);
281281
}
282282
}

app/V1Module/presenters/ExercisesPresenter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@ public function actionUpdateDetail(string $id) {
285285
$localization["description"] = $localization["description"] ?? "";
286286

287287
$localized = new LocalizedExercise(
288-
$lang, $localization["name"], $localization["text"], $localization["description"], $externalAssignmentLink ?: null
288+
$lang,
289+
trim(Arrays::get($localization, "name", "")),
290+
trim(Arrays::get($localization, "text", "")),
291+
trim(Arrays::get($localization, "description", "")),
292+
$externalAssignmentLink ?: null
289293
);
290294

291295
$localizations[$lang] = $localized;

app/V1Module/presenters/ShadowAssignmentsPresenter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ public function actionUpdateDetail(string $id) {
172172
}
173173

174174
$localized = new LocalizedShadowAssignment(
175-
$lang, $localization["name"], $localization["text"],
175+
$lang,
176+
trim(Arrays::get($localization, "name", "")),
177+
trim(Arrays::get($localization, "text", "")),
176178
$externalAssignmentLink ?: null
177179
);
178180

0 commit comments

Comments
 (0)