Skip to content
Open
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
2 changes: 1 addition & 1 deletion core/src/OCP/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import $ from 'jquery'
*
* This is a copy of the backend regex in IURLGenerator, make sure to adjust both when changing
*/
const urlRegex = /(\s|^)(https?:\/\/)([-A-Z0-9+_.]+(?::[0-9]+)?(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|$)/ig
const urlRegex = /(\s|^|\]\()(https?:\/\/)([-A-Z0-9+_.]+(?::[0-9]+)?(?:\/[-A-Z0-9+&@#%?=~_|!:,.;\[\()]*)*)(\s|$|\))/ig

/**
* @param {any} content -
Expand Down
18 changes: 14 additions & 4 deletions lib/private/Collaboration/Reference/ReferenceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,20 @@ public function __construct(
*/
public function extractReferences(string $text): array {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should definitely add tests for this method, are you able to do that, or should someone assist/take over?

preg_match_all(IURLGenerator::URL_REGEX, $text, $matches);
$references = $matches[0] ?? [];
return array_map(function ($reference) {
return trim($reference);
}, $references);
// Use capture groups 2 (protocol) and 3 (domain/path) to extract clean URLs
// This excludes the prefix group 1 (\s|\n|^|\]\() and suffix group 4 (\s|\n|$|\))
$references = [];
if (!empty($matches[1]) && !empty($matches[2]) && !empty($matches[3])) {
for ($i = 0; $i < count($matches[2]); $i++) {
$url = $matches[2][$i] . $matches[3][$i];
// If the URL was in markdown syntax [](url), remove the trailing )
if ($matches[1][$i] === '](') {
$url = rtrim($url, ')');
}
$references[] = $url;
}
}
return $references;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/public/IURLGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ interface IURLGenerator {
*
* @since 25.0.0
* @since 29.0.0 changed to match localhost and hostnames with ports
* @since 33.0.0 changed to match URLs in markdown link syntax and square brackets in query parameters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since line also needs to be on URL_REGEX to reflect the change of the value there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also add that those are now part of the match and therefor regex group 2+3 are the actual link going forward and the full match in itself does not have to be a full valid link anymore.

*/
public const URL_REGEX_NO_MODIFIERS = '(\s|\n|^)(https?:\/\/)([-A-Z0-9+_.]+(?::[0-9]+)?(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|\n|$)';
public const URL_REGEX_NO_MODIFIERS = '(\s|\n|^|\]\()(https?:\/\/)([-A-Z0-9+_.]+(?::[0-9]+)?(?:\/[-A-Z0-9+&@#%?=~_|!:,.;\[\()]*)*)(\s|\n|$|\))';

/**
* Returns the URL for a route
Expand Down
Loading