Skip to content

Commit 8fc9ab3

Browse files
apply suggestions from code review (WP-976)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 104a938 commit 8fc9ab3

5 files changed

Lines changed: 9 additions & 6 deletions

File tree

inc/Smartling/Bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ private function initializeBuildInContentTypes(ContainerBuilder $di): void
438438
'smartling-react-app',
439439
plugin_dir_url(__FILE__) . '../../js/app.js',
440440
['wp-element', 'wp-components', 'wp-date'],
441-
static::$pluginVersion . random_int(0, 10000),
441+
static::$pluginVersion,
442442
true,
443443
);
444444
wp_enqueue_style('wp-components');

inc/Smartling/WP/Controller/ContentEditJobController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function initJobApiProxy(): void
7777
$validateRequires = static function ($fieldName) use (&$result, $params) {
7878
$value = trim($params[$fieldName]);
7979

80-
if (!array_key_exists($fieldName, $params) || $value !== '') {
80+
if (!array_key_exists($fieldName, $params) || $value === '') {
8181
$msg = vsprintf('The field \'%s\' cannot be empty', [$fieldName]);
8282
Bootstrap::getLogger()->warning($msg);
8383
$result['status'] = 400;

inc/Smartling/WP/View/BulkSubmit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
data-bulk-submit="true"
6666
data-content-type=""
6767
data-content-id="0"
68-
data-locales='<?= json_encode(array_values($localesData)) ?>'
68+
data-locales='<?= htmlspecialchars(json_encode(array_values($localesData), JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_HEX_TAG), ENT_QUOTES, 'UTF-8') ?>'
6969
data-ajax-url="<?= admin_url('admin-ajax.php') ?>"
7070
data-admin-url="<?= admin_url('admin-ajax.php') ?>"></div>
7171
<div class="postbox-container" style="display:none;">

inc/Smartling/WP/View/ContentEditJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
data-bulk-submit="false"
5959
data-content-type="<?= $data['contentType'] ?? $baseType ?>"
6060
data-content-id="<?= $id ?>"
61-
data-locales='<?= json_encode(array_values($localesData)) ?>'
61+
data-locales='<?= htmlspecialchars(json_encode(array_values($localesData), JSON_HEX_APOS | JSON_HEX_QUOT), ENT_QUOTES, 'UTF-8') ?>'
6262
data-ajax-url="<?= admin_url('admin-ajax.php') ?>"
6363
data-admin-url="<?= admin_url('admin-ajax.php') ?>"></div>
6464
<?php if ($needWrapper) : ?>

js/app.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,16 @@ function JobWizard({ isBulkSubmitPage, contentType, contentId, locales, ajaxUrl,
149149
}
150150
});
151151

152-
if (jobResponse.status > 300) {
152+
if (jobResponse.status >= 400) {
153153
throw new Error(jobResponse.message?.global || 'Failed to create job');
154154
}
155155
data.job.id = jobResponse.data.translationJobUid;
156156
}
157157

158-
await jQuery.post(url, data);
158+
const submissionResponse = await jQuery.post(url, data);
159+
if (submissionResponse.status && submissionResponse.status > 300) {
160+
throw new Error(submissionResponse.message?.global || 'Failed to add content to upload queue.');
161+
}
159162
setSuccess('Content successfully added to upload queue.');
160163
} catch (e) {
161164
setError(e.message || 'Failed adding content to upload queue.');

0 commit comments

Comments
 (0)