Skip to content

Commit 7ae74a0

Browse files
rick-gnousdregad
authored andcommitted
Cgit: fix error with libravatar plugin
The extra <span> tag added by the libravatar plugin triggered a value too long for type character varying(250) error. Modified regex to cover this use case. Use a variable for the pattern to avoid code duplication. Fixes #386 Changes to original contribution: - reworded commit message - added non-capturing regex group for the <span> tag - coding guidelines Signed-off-by: Damien Regad <[email protected]>
1 parent 943bff1 commit 7ae74a0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

SourceCgit/SourceCgit.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,15 @@ public function commit_revision( $p_input ) {
250250
* @return array author / committer
251251
*/
252252
public function commit_author( $p_input ) {
253-
preg_match( "#<tr><th>author</th><td>(.*?)<(.*?)></td><td class='right'>(.*?)</td>#", $p_input, $t_matches);
254-
$t_commit['author'] = trim($t_matches[1]);
253+
$pattern = "<td>(?:.*?</span>)?(.*?) <(.*?@.*?)></td><td class='right'>(.*?)</td>#";
254+
255+
preg_match( "#<tr><th>author</th>" . $pattern, $p_input, $t_matches );
256+
$t_commit['author'] = trim( $t_matches[1] );
255257
$t_commit['author_email'] = $t_matches[2];
256258
$t_commit['date'] = date( 'Y-m-d H:i:s', strtotime( $t_matches[3] ) );
257259

258-
if( preg_match( "#<tr><th>committer</th><td>(.*?)<(.*?)></td><td class='right'>(.*?)</td>#", $p_input, $t_matches) ) {
259-
$t_commit['committer'] = trim($t_matches[1]);
260+
if( preg_match( "#<tr><th>committer</th>" . $pattern, $p_input, $t_matches ) ) {
261+
$t_commit['committer'] = trim( $t_matches[1] );
260262
$t_commit['committer_email'] = $t_matches[2];
261263
}
262264

0 commit comments

Comments
 (0)