From: Aryeh Gregor Date: Mon, 6 Aug 2018 16:53:45 +0000 (+0300) Subject: Clean up param handling in ApiStashEdit X-Git-Tag: 1.34.0-rc.0~4551^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=0438e942221853ac17c3de0c4214db8589a7e652;p=lhc%2Fweb%2Fwiklou.git Clean up param handling in ApiStashEdit It doesn't make sense to submit both stashedtexthash and text, so requireOnlyOneParameter() is correct. This simplifies the code and gives a more helpful error message. (Previously if both parameters were passed, we would ignore text unless stashedtexthash was empty, in which case we would ignore it.) Change-Id: I306b15eefb6fd4379a3eed88d84113c2e43c4a95 --- diff --git a/includes/api/ApiStashEdit.php b/includes/api/ApiStashEdit.php index 23163c2489..bf956dcbec 100644 --- a/includes/api/ApiStashEdit.php +++ b/includes/api/ApiStashEdit.php @@ -67,11 +67,11 @@ class ApiStashEdit extends ApiBase { ); } - $this->requireAtLeastOneParameter( $params, 'stashedtexthash', 'text' ); + $this->requireOnlyOneParameter( $params, 'stashedtexthash', 'text' ); $text = null; $textHash = null; - if ( strlen( $params['stashedtexthash'] ) ) { + if ( $params['stashedtexthash'] !== null ) { // Load from cache since the client indicates the text is the same as last stash $textHash = $params['stashedtexthash']; if ( !preg_match( '/^[0-9a-f]{40}$/', $textHash ) ) { @@ -82,16 +82,11 @@ class ApiStashEdit extends ApiBase { if ( !is_string( $text ) ) { $this->dieWithError( 'apierror-stashedit-missingtext', 'missingtext' ); } - } elseif ( $params['text'] !== null ) { - // Trim and fix newlines so the key SHA1's match (see WebRequest::getText()) + } else { + // 'text' was passed. Trim and fix newlines so the key SHA1's + // match (see WebRequest::getText()) $text = rtrim( str_replace( "\r\n", "\n", $params['text'] ) ); $textHash = sha1( $text ); - } else { - $this->dieWithError( [ - 'apierror-missingparam-at-least-one-of', - Message::listParam( [ 'stashedtexthash', 'text' ] ), - 2, - ], 'missingparam' ); } $textContent = ContentHandler::makeContent(