Mollywhite has uploaded a new change for review.
https://gerrit.wikimedia.org/r/80326
Change subject: Bug 52310: Disallow empty JSON blocks (don't merge)
......................................................................
Bug 52310: Disallow empty JSON blocks (don't merge)
This patch prevents users from saving an empty JSON block, either
using the book editor, or by adding "{}" in the edit box without
the editor enabled.
Don't merge yet -- I want to double check a few things against the
JSON editor once it's all merged in; I think a patch may be
necessary.
Bug: 52310
Change-Id: Ia602d4900278b305e0fce5fb384516b8fcc86277
---
M includes/JsonSchema.i18n.php
M includes/JsonSchema.php
2 files changed, 7 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BookManagerv2
refs/changes/26/80326/1
diff --git a/includes/JsonSchema.i18n.php b/includes/JsonSchema.i18n.php
index 92ad51a..7c2389d 100644
--- a/includes/JsonSchema.i18n.php
+++ b/includes/JsonSchema.i18n.php
@@ -22,6 +22,7 @@
'jsonschema-invalidnode' => 'Invalid node: expecting "$1", got "$2".
Path: "$3"',
'jsonschema-invalid-missingfield' => 'Missing required field "$1"',
'jsonschema-invalid-notinenum' => 'Value "$1" not in enum for property
$2',
+ 'jsonschema-empty-block' => 'Cannot save an empty block',
);
/** Message documentation (Message documentation)
@@ -35,6 +36,7 @@
'jsonschema-invalidnode' => 'JSON Schema validation error, shown when
object node does not match expected type.',
'jsonschema-invalid-missingfield' => 'JSON Schema validation error,
shown when a required field is missing.',
'jsonschema-invalid-notinenum' => 'JSON Schema validation error, shown
when a value is not in the set of permitted values for a field.',
+ 'jsonschema-empty-block' => 'JSON Schema validation error, shown when
the user tries to submit an empty block of JSON.',
);
/** Asturian (asturianu)
diff --git a/includes/JsonSchema.php b/includes/JsonSchema.php
index 7eff22f..60836ea 100644
--- a/includes/JsonSchema.php
+++ b/includes/JsonSchema.php
@@ -403,6 +403,11 @@
$e = new JsonSchemaException( $msg );
$e->subtype = "validate-fail";
throw( $e );
+ } else if ( $this->parent == null && count( $this->node ) === 0
) {
+ $msg = JsonUtil::uiMessage( 'jsonschema-empty-block' );
+ $e = new JsonSchemaException( $msg );
+ $e->subtype = "validate-fail";
+ throw( $e );
}
$datatype = JsonUtil::getType( $this->node );
$schematype = $this->getType();
--
To view, visit https://gerrit.wikimedia.org/r/80326
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia602d4900278b305e0fce5fb384516b8fcc86277
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BookManagerv2
Gerrit-Branch: master
Gerrit-Owner: Mollywhite <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits