Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Sources/Autolinker.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,11 @@ public function detectUrls(string $string, bool $plaintext_only = false): array

// An entity right after the URL can break the autolinker.
$this->setEntitiesRegex();
$string = preg_replace('~(' . $this->entities_regex . ')*(?=\s|$)~u', ' ', $string);
$string = preg_replace_callback(
'~(' . $this->entities_regex . ')*(?=\s|$)~u',
fn ($matches) => str_repeat(' ', strlen($matches[0])),
$string,
);

$this->setUrlRegex();

Expand Down Expand Up @@ -412,7 +416,7 @@ public function detectUrls(string $string, bool $plaintext_only = false): array

// Overwrite all BBC markup elements.
$string = preg_replace_callback(
'/\[[^\]]*\]/i' . ($this->encoding === 'UTF-8' ? 'u' : ''),
'~\[/?' . Parser::getBBCodeTagsRegex() . '[^\]]*\]~i' . ($this->encoding === 'UTF-8' ? 'u' : ''),
fn ($matches) => str_repeat(' ', strlen($matches[0])),
$string,
);
Expand Down Expand Up @@ -786,7 +790,7 @@ public static function createJavaScriptFile(bool $force = false): void
$regexes['email'] = self::load()->getJavaScriptEmailRegex();

// Don't autolink if the URL is inside a Markdown link construct.
$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]*))' : '';
$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(?:=[^\]]*)?\])';

foreach ($regexes as $key => $value) {
$js[] = 'autolinker_regexes.set(' . Utils::escapeJavaScript($key) . ', new RegExp(' . Utils::escapeJavaScript($md_lookbehind . $value) . ', "giu"));';
Expand Down
10 changes: 10 additions & 0 deletions Sources/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,16 @@ public static function getSigTags(): array
return BBcodeParser::getSigTags();
}

/**
* Gets a regular expression to match all known BBC tags.
*
* @return string Regular expression to match all BBCode tags.
*/
public static function getBBCodeTagsRegex(): string
{
return BBcodeParser::load()->getAllTagsRegex();
}

/**
* Highlight any code.
*
Expand Down
4 changes: 2 additions & 2 deletions Themes/default/scripts/jquery.sceditor.smf.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@
url[0] = '//' + url[0];
}

// Wrap the URL in BBC tags.
editor.insert('[' + bbc_tag + '="' + url[0] + '"]', '[/' + bbc_tag + ']');
// Insert the URL.
editor.wysiwygEditorInsertHtml('<a data-type="' + bbc_tag + '" href="' + url[0] + '">' + url[0] + '</a>');
}

// Helper for this.signalKeydownEvent.
Expand Down
Loading