Skip to content

Commit

Permalink
trim whitespace better
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Aug 18, 2024
1 parent 5725510 commit 7ad1f6b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ public function onPullRequest(GitHubEvent $event)
$prPrefix .= '['.$label.']';
}

// Clean string from all HTML chars and remove whitespace at the beginning
$prTitle = preg_replace('@^[\h\s]+@u', '', html_entity_decode($prTitle));

// Add back labels
$prTitle = trim($prPrefix.' '.trim(str_replace(' ', '', $prTitle)));
$prTitle = trim($prPrefix.' '.trim($prTitle));
if ($originalTitle === $prTitle) {
return;
}
Expand Down
17 changes: 17 additions & 0 deletions tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,21 @@ public function testRemoveLabel()
$this->assertSame(1234, $responseData['pull_request']);
$this->assertSame('[Console] [Random] Foo normal title', $responseData['new_title']);
}

public function testExtraBlankSpace()
{
$event = new GitHubEvent(['action' => 'labeled', 'number' => 57753, 'pull_request' => []], $this->repository);
$this->pullRequestApi->method('show')->willReturn([
'title' => '[ErrorHandler] restrict the maximum length of the X-Debug-Exception header',
'labels' => [
['name' => 'ErrorHandler', 'color' => 'dddddd'],
],
]);

$this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST);
$responseData = $event->getResponseData();
$this->assertCount(2, $responseData);
$this->assertSame(57753, $responseData['pull_request']);
$this->assertSame('[ErrorHandler] restrict the maximum length of the X-Debug-Exception header', $responseData['new_title']);
}
}

0 comments on commit 7ad1f6b

Please sign in to comment.