Unfortunately, I have discovered another issue after testing this: it does not seem possible to delete the contents of the field again. If I try to delete it, an error message appears stating that the value is invalid and the empty field will not be saved.
Yes, that is because the validate function is too restrictive:
It should imho look like this:
/**
* Validate the URL input
*
* @param {string} input the input
* @return {boolean}
*/
export function validateUrl(input) {
// Treat null/undefined/empty (after trimming) as valid so the user can remove the URL
if (input === null || input === undefined) return true
const value = String(input).trim()
if (value === '') return true
try {
// eslint-disable-next-line no-new
new URL(value)
return true
} catch (e) {
return false
}
}
If you want users to be able to enter www.example.com without https://, you can automatically prepend https:// before using new URL():
(untested):
/**
* Validate the URL input, accept empty values and scheme-less hosts
*
* @param {string} input the input
* @return {boolean}
*/
export function validateUrl(input) {
// Treat null/undefined/empty (after trimming) as valid so the user can remove the URL
if (input === null || input === undefined) return true
let value = String(input).trim()
if (value === '') return true
// If there's no scheme like "http:", assume https
// This accepts inputs like "www.example.com" or "example.com"
if (!/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(value)) {
value = 'https://' + value
}
try {
// eslint-disable-next-line no-new
new URL(value)
return true
} catch (e) {
return false
}
}
In the last example, https:// is only prepended if there is no scheme in the input. If the user enters http://example.com, http:// is retained, and new URL() should validate it normally.
@bb77: If you want to remove the Website data from your personal settings, you should remove it from the database with this query (replace $user_id):
MySQL:
UPDATE oc_accounts SET data = JSON_SET(data, '$.website.value', '') WHERE uid = '$user_id';
Although it’s not really an issue for me since I only tried it on a test instance, it’s of course still good to know.
However, I would also consider it a bug because deleting an entry should definitely be possible from the web UI.
Well not sure if that’s a good idea, because there might actually still be people that actually have a website that is served via HTTP, although they probably shouldn’t
Ah sorry, I changed my mind and decided to open one anyway.
However, it would probably have been better if we had left yours open, since you have all the details right in there. Let me know if you want to reopen it, and I’ll close mine.