What are the restrictions on GSetting path names?

257 Views Asked by At

I've read in the GSettings documentation that:

Key names are restricted to lowercase characters, numbers and '-'. Furthermore, the names must begin with a lowercase character, must not end with a '-', and must not contain consecutive dashes

But there are no notes on path names, other that not including consecutive slashes (/). My use case is generating subdirectories (from a relocatable schema) for device based settings and I'm wondering if I should be sanitising the strings of any characters.

1

There are 1 best solutions below

1
On BEST ANSWER

There are notes on path names, and they are complete:

Paths must start with and end with a forward slash character ('/') and must not contain two sequential slash characters. Paths should be chosen based on a domain name associated with the program or library to which the settings belong. Examples of paths are "/org/gtk/settings/file-chooser/" and "/ca/desrt/dconf-editor/". Paths should not start with "/apps/", "/desktop/" or "/system/" as they often did in GConf.

(from the documentation).

The code which validates them is the following:

static gboolean
path_is_valid (const gchar *path)
{
  if (!path)
    return FALSE;

  if (path[0] != '/')
    return FALSE;

  if (!g_str_has_suffix (path, "/"))
    return FALSE;

  return strstr (path, "//") == NULL;
}

(from gsettings.c).

So the documentation is complete — it mentions everything the code checks.

Depending on how your devices are identified, you probably do want to do some escaping or sanitisation to remove slashes just in case you would have ended up with consecutive slashes. Other than that, you only need to sanitise things to make them human readable and easy to debug, if you want.