Skip to content

Commit ecfede9

Browse files
authored
trim whitespace better (#234)
1 parent f2e05f5 commit ecfede9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Subscriber/AutoUpdateTitleWithLabelSubscriber.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ public function onPullRequest(GitHubEvent $event)
7676
$prPrefix .= '['.$label.']';
7777
}
7878

79+
// Clean string from all HTML chars and remove whitespace at the beginning
80+
$prTitle = preg_replace('@^[\h\s]+@u', '', html_entity_decode($prTitle));
81+
7982
// Add back labels
80-
$prTitle = trim($prPrefix.' '.trim(str_replace(' ', '', $prTitle)));
83+
$prTitle = trim($prPrefix.' '.trim($prTitle));
8184
if ($originalTitle === $prTitle) {
8285
return;
8386
}

tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,21 @@ public function testRemoveLabel()
112112
$this->assertSame(1234, $responseData['pull_request']);
113113
$this->assertSame('[Console] [Random] Foo normal title', $responseData['new_title']);
114114
}
115+
116+
public function testExtraBlankSpace()
117+
{
118+
$event = new GitHubEvent(['action' => 'labeled', 'number' => 57753, 'pull_request' => []], $this->repository);
119+
$this->pullRequestApi->method('show')->willReturn([
120+
'title' => '[ErrorHandler] restrict the maximum length of the X-Debug-Exception header',
121+
'labels' => [
122+
['name' => 'ErrorHandler', 'color' => 'dddddd'],
123+
],
124+
]);
125+
126+
$this->dispatcher->dispatch($event, GitHubEvents::PULL_REQUEST);
127+
$responseData = $event->getResponseData();
128+
$this->assertCount(2, $responseData);
129+
$this->assertSame(57753, $responseData['pull_request']);
130+
$this->assertSame('[ErrorHandler] restrict the maximum length of the X-Debug-Exception header', $responseData['new_title']);
131+
}
115132
}

0 commit comments

Comments
 (0)