mirror of https://github.com/keeweb/keeweb.git
filtering protocols in the url field
This commit is contained in:
parent
38c3a46395
commit
2f214b25c7
|
@ -1,22 +1,35 @@
|
|||
import { FieldViewText } from 'views/fields/field-view-text';
|
||||
import { escape } from 'util/fn';
|
||||
|
||||
const AllowedProtocols = ['http:', 'https:', 'ftp:', 'ftps:', 'mailto:'];
|
||||
|
||||
class FieldViewUrl extends FieldViewText {
|
||||
displayUrlRegex = /^https:\/\//i;
|
||||
cssClass = 'url';
|
||||
|
||||
renderValue(value) {
|
||||
return value
|
||||
? '<a href="' +
|
||||
escape(this.fixUrl(value)) +
|
||||
'" rel="noreferrer noopener" target="_blank">' +
|
||||
escape(this.displayUrl(value)) +
|
||||
'</a>'
|
||||
: '';
|
||||
try {
|
||||
return value
|
||||
? '<a href="' +
|
||||
escape(this.fixUrl(value)) +
|
||||
'" rel="noreferrer noopener" target="_blank">' +
|
||||
escape(this.displayUrl(value)) +
|
||||
'</a>'
|
||||
: '';
|
||||
} catch (e) {
|
||||
return escape(value);
|
||||
}
|
||||
}
|
||||
|
||||
fixUrl(url) {
|
||||
return url.indexOf(':') < 0 ? 'https://' + url : url;
|
||||
const proto = new URL(url, 'dummy://').protocol;
|
||||
if (proto === 'dummy:') {
|
||||
return 'https://' + url;
|
||||
}
|
||||
if (!AllowedProtocols.includes(proto)) {
|
||||
throw new Error('Bad url');
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
displayUrl(url) {
|
||||
|
|
Loading…
Reference in New Issue