Skip to content

Commit ae758d1

Browse files
Fix error during missing magazine parsing (#1525)
Co-authored-by: Melroy van den Berg <[email protected]>
1 parent d8071c7 commit ae758d1

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/Markdown/Listener/CacheMarkdownListener.php

+13-5
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,23 @@ private function getMissingMentionsFromMarkdown(string $markdown): array
146146
/** @return string[] */
147147
private function getMissingMagazineMentions(string $markdown): array
148148
{
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), '&nbsp;', $markdown));
150151
$missingCommunityMentions = [];
151152
foreach ($words as $word) {
152153
$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)) {
154157
$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()]);
158166
}
159167
}
160168
}

0 commit comments

Comments
 (0)