3030}
3131
3232function str_replace_deep ($ search , $ replace , $ subject ) {
33+ if (is_null ($ subject ))
34+ return '' ;
3335 if (is_array ($ subject ))
3436 {
3537 foreach ($ subject as &$ oneSubject )
@@ -158,7 +160,8 @@ static public function extraRaise($params) {
158160 $ key = $ webhook_infos [static ::getTargetFieldName ()];
159161 $ url = $ webhook_infos ['additionnaloption ' ]['address ' ];
160162 $ url = NotificationTemplate::process ($ webhook_infos ['additionnaloption ' ]['address ' ], $ data ); // substitute variables in url
161- $ url = str_replace (["\n" , "\r" , "\t" ], ['' , '' , '' ], htmlentities ($ url )); // translate HTML-significant characters and suppress remaining escape characters
163+ // $url = str_replace(["\n", "\r", "\t"], ['', '', ''], htmlentities($url)); // translate HTML-significant characters and suppress remaining escape characters
164+ $ url = str_replace (["\n" , "\r" , "\t" ], ['' , '' , '' ], $ url ); // suppress remaining escape characters
162165 if ($ template_datas = $ template ->getByLanguage ($ webhook_infos ['language ' ]))
163166 {
164167 $ template_datas = Sanitizer::unsanitize ($ template_datas ); // unescape html from DB
@@ -169,11 +172,12 @@ static public function extraRaise($params) {
169172 $ template = $ template_datas ['content_html ' ];
170173
171174 // escape double quotes (as the LF, CR and TAB characters)
172- $ data = str_replace_deep (["\n" , "\r" , "\t" , '" ' ], ['\\n ' , '\\r ' , '\\t ' , '\\" ' ], $ data );
175+ $ data = str_replace_deep (["\\" , "\ n" , "\r" , "\t" , '" ' ], ['\\\\' , '\\n ' , '\\r ' , '\\t ' , '\\" ' ], $ data );
173176
174177 $ content = NotificationTemplate::process ($ template , $ data );
175178 $ curl = curl_init ($ url );
176- $ secrettype = $ webhook_infos ['additionnaloption ' ]['plugin_webhook_secrettypes_id ' ];
179+ $ secrettype = $ webhook_infos ['additionnaloption ' ]['plugin_webhook_secrettypes_id ' ];
180+ $ headers = array ();
177181 switch ($ secrettype )
178182 {
179183 case 1 : // No Authentication
@@ -213,7 +217,7 @@ static public function extraRaise($params) {
213217
214218 $ status = curl_getinfo ($ curl , CURLINFO_HTTP_CODE );
215219
216- if ( $ status != 200 && $ status != 201 ) {
220+ if ( $ status < 200 || $ status >= 300 ) {
217221 Session::addMessageAfterRedirect ("<font color='red'> " ."Error: call to URL $ url failed with status $ status, response $ json_response, curl_error " . curl_error ($ curl ) . ", curl_errno " . curl_errno ($ curl )."</font> " , false , ERROR );
218222 Toolbox::logInFile ("webhook " , "Error : call to URL $ url failed with status $ status, response $ json_response, curl_error " . curl_error ($ curl ) . ", curl_errno " . curl_errno ($ curl ).PHP_EOL ."HTTP Headers : " .print_r ($ headers ,true ).PHP_EOL ."POST Content : " .print_r ($ content ,true ).PHP_EOL );
219223 }
0 commit comments