From f2756da0a413f8b9787248dba22892f072b42361 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Wed, 14 Aug 2019 13:19:14 +0200 Subject: [PATCH] Add missing tag name in error message When creating a new issue via REST API with a non-existing tag name, the error message generated by mci_tag_set_for_issue() did not include the tag's name. This was caused by reusing the $t_tag variable to store the return value of tag_get_by_name(), so the original data is no longer available when the exception is thrown. Same problem in IssueAddCommand::validate() if the user attempting to create the issue does not have the required privileges to create tags, this time due to usage of an uninitialized variable. Fixes #25996 --- api/soap/mc_tag_api.php | 8 ++++---- core/commands/IssueAddCommand.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/soap/mc_tag_api.php b/api/soap/mc_tag_api.php index faf19ca549..521de2fff1 100644 --- a/api/soap/mc_tag_api.php +++ b/api/soap/mc_tag_api.php @@ -167,15 +167,15 @@ function mci_tag_set_for_issue ( $p_issue_id, array $p_tags, $p_user_id ) { ); } } else if( isset( $t_tag['name'] ) ) { - $t_tag = tag_get_by_name( $t_tag['name'] ); - if( $t_tag === false ) { + $t_get_tag = tag_get_by_name( $t_tag['name'] ); + if( $t_get_tag === false ) { throw new ClientException( - "Tag {$t_tag['name']} not found.", + "Tag '{$t_tag['name']}' not found.", ERROR_TAG_NOT_FOUND ); } - $t_tag_id = $t_tag['id']; + $t_tag_id = $t_get_tag['id']; } else { throw new ClientException( 'Tag without id or name.', diff --git a/core/commands/IssueAddCommand.php b/core/commands/IssueAddCommand.php index d7b2b1fe23..9bf2106c36 100644 --- a/core/commands/IssueAddCommand.php +++ b/core/commands/IssueAddCommand.php @@ -221,7 +221,7 @@ function validate() { foreach( $t_issue['tags'] as $t_tag ) { if( $t_tag['id'] === -1 ) { throw new ClientException( - sprintf( "User '%d' can't create tag '%s'.", $this->user_id, $t_new_tag ), + sprintf( "User '%d' can't create tag '%s'.", $this->user_id, $t_tag['name'] ), ERROR_TAG_NOT_FOUND ); } }