@@ -384,7 +384,11 @@ public function detectUrls(string $string, bool $plaintext_only = false): array
384384
385385 // An entity right after the URL can break the autolinker.
386386 $ this ->setEntitiesRegex ();
387- $ string = preg_replace ('~( ' . $ this ->entities_regex . ')*(?=\s|$)~u ' , ' ' , $ string );
387+ $ string = preg_replace_callback (
388+ '~( ' . $ this ->entities_regex . ')*(?=\s|$)~u ' ,
389+ fn ($ matches ) => str_repeat (' ' , strlen ($ matches [0 ])),
390+ $ string ,
391+ );
388392
389393 $ this ->setUrlRegex ();
390394
@@ -412,7 +416,7 @@ public function detectUrls(string $string, bool $plaintext_only = false): array
412416
413417 // Overwrite all BBC markup elements.
414418 $ string = preg_replace_callback (
415- '/\[ [^\]]*\]/ i ' . ($ this ->encoding === 'UTF-8 ' ? 'u ' : '' ),
419+ '~\[/? ' . Parser:: getBBCodeTagsRegex () . ' [^\]]*\]~ i ' . ($ this ->encoding === 'UTF-8 ' ? 'u ' : '' ),
416420 fn ($ matches ) => str_repeat (' ' , strlen ($ matches [0 ])),
417421 $ string ,
418422 );
@@ -786,7 +790,7 @@ public static function createJavaScriptFile(bool $force = false): void
786790 $ regexes ['email ' ] = self ::load ()->getJavaScriptEmailRegex ();
787791
788792 // Don't autolink if the URL is inside a Markdown link construct.
789- $ md_lookbehind = !empty (Config::$ modSettings ['enableMarkdown ' ]) ? '(?<!\[[^\]]*\](?:\(|:[ \t\u00A0\u1680\u180E\u2000-\u200A\u202F\u205F\u3000]*\n?[ \t\u00A0\u1680\u180E\u2000-\u200A\u202F\u205F\u3000]*)) ' : '' ;
793+ $ md_lookbehind = !empty (Config::$ modSettings ['enableMarkdown ' ]) ? '(?<!\[[^\]]*\](?:\(|:[ \t\u00A0\u1680\u180E\u2000-\u200A\u202F\u205F\u3000]*\n?[ \t\u00A0\u1680\u180E\u2000-\u200A\u202F\u205F\u3000]*)|\[i?url(?:=[^\]]*)?\]) ' : '(?<!\[i?url(?:=[^\]]*)?\]) ' ;
790794
791795 foreach ($ regexes as $ key => $ value ) {
792796 $ js [] = 'autolinker_regexes.set( ' . Utils::escapeJavaScript ($ key ) . ', new RegExp( ' . Utils::escapeJavaScript ($ md_lookbehind . $ value ) . ', "giu")); ' ;
0 commit comments