From 4c2fc2570ae75d21fd279e512d0e506ac6218a0a Mon Sep 17 00:00:00 2001 From: nanaya Date: Tue, 24 Sep 2024 15:12:36 +0900 Subject: [PATCH 1/2] Prevent passing in null for str replace --- app/Libraries/Markdown/Osu/DocumentProcessor.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Libraries/Markdown/Osu/DocumentProcessor.php b/app/Libraries/Markdown/Osu/DocumentProcessor.php index cccd53aa6f3..94b865c989d 100644 --- a/app/Libraries/Markdown/Osu/DocumentProcessor.php +++ b/app/Libraries/Markdown/Osu/DocumentProcessor.php @@ -148,7 +148,9 @@ private function loadToc() } $title = presence($this->getText($this->node)); - $slug = $this->node->data['attributes']['id'] ?? presence(mb_strtolower(str_replace(' ', '-', $title))) ?? 'page'; + $slug = $this->node->data['attributes']['id'] + ?? presence(mb_strtolower(str_replace(' ', '-', $title ?? ''))) + ?? 'page'; if (array_key_exists($slug, $this->tocSlugs)) { $this->tocSlugs[$slug] += 1; From 3622aea992baa5b1ed0ffa5babf25bf2ac752d2f Mon Sep 17 00:00:00 2001 From: nanaya Date: Tue, 24 Sep 2024 15:14:07 +0900 Subject: [PATCH 2/2] Use strtr instead --- app/Libraries/Markdown/Osu/DocumentProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Libraries/Markdown/Osu/DocumentProcessor.php b/app/Libraries/Markdown/Osu/DocumentProcessor.php index 94b865c989d..579ec1a65f5 100644 --- a/app/Libraries/Markdown/Osu/DocumentProcessor.php +++ b/app/Libraries/Markdown/Osu/DocumentProcessor.php @@ -149,7 +149,7 @@ private function loadToc() $title = presence($this->getText($this->node)); $slug = $this->node->data['attributes']['id'] - ?? presence(mb_strtolower(str_replace(' ', '-', $title ?? ''))) + ?? presence(mb_strtolower(strtr($title ?? '', ' ', '-'))) ?? 'page'; if (array_key_exists($slug, $this->tocSlugs)) {