Invalid information is stored and cannot be deleted

Which version of Nextcloud are you using? When I tested it on a 31.0.8 instance, it complained when I entered an address without a scheme.

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';

(PostgreSQL is different)

and then run

occ dav:sync-system-addressbook

After that the “Website” field is empty again.

h.t.h.


ernolf

1 Like

@ernolf to the rescue :slight_smile: :+1:

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. :slight_smile:

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 :wink:

1 Like

.. that’s why I left the option to use http:// in that code snippet. It just has to be entered explicitly.

Ah, okay. In that case, it would probably be a good idea to submit it as a pull request. :slight_smile:

By the way, the issue that the field cannot be deleted should probably be reported, as it still exists in Nextcloud 32 RC1.

I have opened an issue: [Bug]: Contents of the "Website" field under "Personal settings" -> "Personlal info" cannot be deleted. · Issue #55003 · nextcloud/server · GitHub

2 Likes

Ups! I did as well :flushed:

.. but I marked mine as duplicate now and closed it.

:+1:

Ah sorry, I changed my mind and decided to open one anyway. :wink:

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.

No, no more noise now, that’s fine how it is! :+1:

1 Like