Skip to content

Commit 9a53ae4

Browse files
committed
Cleaned up code - some adjustments to selected files
The following adjustments were made: - Files should end with a newline (PHP:S113) - Control structures should use curly braces (PHP:S121) - Mergeable "if" statements should be combined (PHP:S1066) - Lines should not end with trailing whitespaces (PHP:S1131) - Use empty() to check whether the array is empty or not (PHP:S1155) - Unused function parameters should be removed (PHP:S1172) - Unused local variables should be removed (PHP:S1481) - PHP keywords and constants "true", "false", "null" should be lower case (PHP:S1781) - Unused assignments should be removed (PHP:S1854) - "require_once" and "include_once" should be used instead of "require" and "include" (PHP:S2003) - "&&" and "||" should be used (PHP:S2010)
1 parent 929f0d4 commit 9a53ae4

6 files changed

Lines changed: 459 additions & 531 deletions

File tree

lib/ajax/getreqspeclog.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
2-
/**
2+
/**
33
* TestLink Open Source Project - http://testlink.sourceforge.net/
4-
*
4+
*
55
* @filesource getreqspeclog.php
66
* @author Francisco Mancardi
7-
*
7+
*
88
* @internal Revisions:
99
*/
1010
require_once '../../config.inc.php';
@@ -31,4 +31,4 @@
3131
$info = lang_get("empty_log_message");
3232
}
3333
}
34-
echo $info;
34+
echo $info;

lib/ajax/gettprojectnodes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ function display_children($dbHandler,$root_node,$parent,$filter_node,$tcprefix,$
179179

180180
/**
181181
*
182+
* @param string $idList
183+
* @param array $tcIDs
182184
*/
183185
function getAllTCasesID($idList,&$tcIDs) {
184186

lib/attachments/attachmentdownload.php

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* TestLink Open Source Project - http://testlink.sourceforge.net/
4-
* This script is distributed under the GNU General Public License 2 or later.
3+
* TestLink Open Source Project - http://testlink.sourceforge.net/
4+
* This script is distributed under the GNU General Public License 2 or later.
55
*
66
* Downloads the attachment by a given id
77
*
@@ -13,7 +13,7 @@
1313
require_once '../functions/common.php';
1414
require_once '../functions/attachments.inc.php';
1515

16-
// This way can be called without _SESSION,
16+
// This way can be called without _SESSION,
1717
// this is useful for reports
1818
// testlinkInitPage($db,false,true);
1919
// But it seems is creating this CVE https://nvd.nist.gov/vuln/detail/CVE-2022-35195
@@ -30,7 +30,7 @@
3030
if ($attachInfo) {
3131
switch ($args->opmode) {
3232
case 'API':
33-
// want to check if apikey provided is right
33+
// want to check if apikey provided is right
3434
// for attachment context
3535
// - test project api key:
3636
// is needed to get attachments for:
@@ -40,7 +40,7 @@
4040
// is needed to get attacments for:
4141
// test case executions
4242
// test specifications ( access to parent data - OK!)
43-
//
43+
//
4444
// What kind of attachments I've got ?
4545
$doIt = false;
4646
$attContext = $attachInfo['fk_table'];
@@ -56,19 +56,16 @@
5656
"WHERE id = " . intval($attachInfo['fk_id']);
5757

5858
$rs = $db->get_recordset($sql);
59-
if (!is_null($rs)) {
60-
if($rs['0']['testplan_id'] == $item['id']) {
61-
// GOOD !
59+
if (!is_null($rs) && $rs['0']['testplan_id'] == $item['id']) {
6260
$doIt = true;
63-
}
64-
}
65-
}
61+
}
62+
}
6663
break;
6764
}
6865
break;
6966

7067
case 'GUI':
71-
default:
68+
default:
7269
$doIt = true;
7370
break;
7471
}
@@ -77,17 +74,16 @@
7774
if ($doIt) {
7875
$content = '';
7976
$getContent = true;
80-
if( $args->opmode !== 'API' && $args->skipCheck !== 0
81-
&& $args->skipCheck !== false) {
77+
if( $args->opmode !== 'API' && $args->skipCheck !== 0 && $args->skipCheck !== false) {
8278
if( $args->skipCheck != hash('sha256',$attachInfo['file_name']) ) {
8379
$getContent = false;
84-
}
85-
}
80+
}
81+
}
8682

8783
if ($getContent) {
8884
$content = $fileRepo->getAttachmentContent($args->id,
8985
$attachInfo);
90-
}
86+
}
9187

9288
if ($content != "") {
9389

@@ -100,8 +96,7 @@
10096

10197
$what2do = "Content-Disposition: inline;";
10298
// is SVG?
103-
if (strripos($content, "<!DOCTYPE svg") !== FALSE
104-
|| strripos($content, "<svg") !== FALSE) {
99+
if (strripos($content, "<!DOCTYPE svg") !== false || strripos($content, "<svg") !== false) {
105100
if (!XSS_StringScriptSafe($content)) {
106101
$what2do = "Content-Disposition: attachment;";
107102
}
@@ -110,20 +105,19 @@
110105
@ob_end_clean();
111106
header('Pragma: public');
112107
header("Cache-Control: ");
113-
if (!(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on" && preg_match("/MSIE/",$_SERVER["HTTP_USER_AGENT"]))) {
108+
if (!(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on" && preg_match("/MSIE/",$_SERVER["HTTP_USER_AGENT"]))) {
114109
header('Pragma: no-cache');
115110
}
116111
header('Content-Type: '. $attachInfo['file_type']);
117112
header('Content-Length: '.$attachInfo['file_size']);
118113

119-
header( $what2do .
120-
" filename=\"{$attachInfo['file_name']}\"");
114+
header( $what2do . " filename=\"{$attachInfo['file_name']}\"");
121115
header("Content-Description: Download Data");
122116

123117
echo $content;
124118
exit();
125-
}
126-
}
119+
}
120+
}
127121
}
128122
}
129123

@@ -138,7 +132,7 @@ function init_args(&$dbHandler)
138132
{
139133
// id (attachments.id) of the attachment to be downloaded
140134
$iParams = array('id' => array(tlInputParameter::INT_N),
141-
'apikey' => array(tlInputParameter::STRING_N,64),
135+
'apikey' => array(tlInputParameter::STRING_N,64),
142136
'skipCheck' => array(tlInputParameter::STRING_N,1,64));
143137

144138
$args = new stdClass();
@@ -149,7 +143,7 @@ function init_args(&$dbHandler)
149143
if( is_null($args->skipCheck) || $args->skipCheck === 0 )
150144
{
151145
$args->skipCheck = false;
152-
}
146+
}
153147

154148
// var_dump($args->skipCheck);die();
155149
// using apikey lenght to understand apikey type
@@ -161,7 +155,7 @@ function init_args(&$dbHandler)
161155
{
162156
$args->opmode = 'API';
163157
$args->skipCheck = true;
164-
}
158+
}
165159
return $args;
166160
}
167161

@@ -173,4 +167,4 @@ function init_args(&$dbHandler)
173167
function checkRights(&$db,&$user)
174168
{
175169
return config_get("attachments")->enabled;
176-
}
170+
}

0 commit comments

Comments
 (0)