From 277a603511cfad1315949bcd9c192231b24f7027 Mon Sep 17 00:00:00 2001 From: Steven Fox <62109327+steven-fox@users.noreply.github.com> Date: Sun, 4 Aug 2024 11:51:35 -0400 Subject: [PATCH] feat(hashtags) do not alter #... found within code/pre blocks --- .../HashtagProviderParsable.php | 4 ++-- tests/Unit/Services/ContentProvidersTest.php | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/Services/ParsableContentProviders/HashtagProviderParsable.php b/app/Services/ParsableContentProviders/HashtagProviderParsable.php index 2df4d337e..3d8599349 100644 --- a/app/Services/ParsableContentProviders/HashtagProviderParsable.php +++ b/app/Services/ParsableContentProviders/HashtagProviderParsable.php @@ -14,10 +14,10 @@ public function parse(string $content): string { return (string) preg_replace_callback( - '/(]*>.*?<\/a>)|(?]*>.*?<\/\2>)|(? $matches[1] !== '' ? $matches[1] - : '#'.$matches[2].'', + : '#'.$matches[3].'', $content ); } diff --git a/tests/Unit/Services/ContentProvidersTest.php b/tests/Unit/Services/ContentProvidersTest.php index 2f39932b0..9cb734082 100644 --- a/tests/Unit/Services/ContentProvidersTest.php +++ b/tests/Unit/Services/ContentProvidersTest.php @@ -276,7 +276,19 @@ 'parsed' => 'Existing link with #segment and a #hashtag.', ], [ - 'content' => 'It'll work with html escapes.', - 'parsed' => 'It'll work with html escapes.', + 'content' => 'It'll work with html escapes.', + 'parsed' => 'It'll work with html escapes.', + ], + [ + 'content' => 'It works with
+ multiline $codeBlocks = true;
+ #comment
+
+ #hashtag',
+ 'parsed' => 'It works with
+ multiline $codeBlocks = true;
+ #comment
+
+ #hashtag',
],
]);