@@ -146,15 +146,23 @@ private function getMissingMentionsFromMarkdown(string $markdown): array
146
146
/** @return string[] */
147
147
private function getMissingMagazineMentions (string $ markdown ): array
148
148
{
149
- $ words = preg_split ('/[ \n\[\]()]/ ' , $ markdown );
149
+ // No-break space is causing issues with word splitting. So replace a no-break (0xc2 0xa0) by a normal space first.
150
+ $ words = preg_split ('/[ \n\[\]()]/ ' , str_replace (\chr (194 ).\chr (160 ), ' ' , $ markdown ));
150
151
$ missingCommunityMentions = [];
151
152
foreach ($ words as $ word ) {
152
153
$ matches = null ;
153
- if (preg_match ('/ ' .CommunityLinkParser::COMMUNITY_REGEX .'/ ' , $ word , $ matches )) {
154
+ // Remove newline (\n), tab (\t), carriage return (\r), etc.
155
+ $ word2 = preg_replace ('/[[:cntrl:]]/ ' , '' , $ word );
156
+ if (preg_match ('/ ' .CommunityLinkParser::COMMUNITY_REGEX .'/ ' , $ word2 , $ matches )) {
154
157
$ apId = "$ matches [1 ]@ $ matches [2 ]" ;
155
- $ magazine = $ this ->magazineRepository ->findOneBy (['apId ' => $ apId ]);
156
- if (!$ magazine ) {
157
- $ missingCommunityMentions [] = $ apId ;
158
+ $ this ->logger ->debug ("searching for magazine '{m}', original word: '{w}', word without cntrl: '{w2}' " , ['m ' => $ apId , 'w ' => $ word , 'w2 ' => $ word2 ]);
159
+ try {
160
+ $ magazine = $ this ->magazineRepository ->findOneBy (['apId ' => $ apId ]);
161
+ if (!$ magazine ) {
162
+ $ missingCommunityMentions [] = $ apId ;
163
+ }
164
+ } catch (\Exception $ e ) {
165
+ $ this ->logger ->error ('An error occurred while looking for magazine "{m}": {t} - {msg} ' , ['m ' => $ apId , 't ' => \get_class ($ e ), 'msg ' => $ e ->getMessage ()]);
158
166
}
159
167
}
160
168
}
0 commit comments