aboutsummaryrefslogtreecommitdiffstats
path: root/core/src/OCP/comments.js
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/OCP/comments.js')
-rw-r--r--core/src/OCP/comments.js26
1 files changed, 18 insertions, 8 deletions
diff --git a/core/src/OCP/comments.js b/core/src/OCP/comments.js
index 2e12accddce..34699a477d1 100644
--- a/core/src/OCP/comments.js
+++ b/core/src/OCP/comments.js
@@ -1,10 +1,6 @@
/**
- * @copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
import $ from 'jquery'
@@ -12,22 +8,33 @@ import $ from 'jquery'
/*
* Detects links:
* Either the http(s) protocol is given or two strings, basically limited to ascii with the last
- * word being at least one digit long,
+ * word being at least one digit long,
* followed by at least another character
*
* The downside: anything not ascii is excluded. Not sure how common it is in areas using different
* alphabets… the upside: fake domains with similar looking characters won't be formatted as links
+ *
+ * This is a copy of the backend regex in IURLGenerator, make sure to adjust both when changing
*/
-const urlRegex = /(\s|^)(https?:\/\/)?((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|$)/ig
+const urlRegex = /(\s|^)(https?:\/\/)([-A-Z0-9+_.]+(?::[0-9]+)?(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|$)/ig
+/**
+ * @param {any} content -
+ */
export function plainToRich(content) {
return this.formatLinksRich(content)
}
+/**
+ * @param {any} content -
+ */
export function richToPlain(content) {
return this.formatLinksPlain(content)
}
+/**
+ * @param {any} content -
+ */
export function formatLinksRich(content) {
return content.replace(urlRegex, function(_, leadingSpace, protocol, url, trailingSpace) {
let linkText = url
@@ -41,6 +48,9 @@ export function formatLinksRich(content) {
})
}
+/**
+ * @param {any} content -
+ */
export function formatLinksPlain(content) {
const $content = $('<div></div>').html(content)
$content.find('a').each(function() {