guuid: Remove support for curly braces and URN UUIDs

As we currently cannot generate UUIDs with curly braces, or as URNs,
remove those from the possible valid UUIDs.

We do this separately to make it easier to re-add later, should we want
to enhance the coverage of our UUID functions.

https://bugzilla.gnome.org/show_bug.cgi?id=639078
This commit is contained in:
Bastien Nocera 2017-02-03 14:27:21 +01:00
parent 215c9b7951
commit 4b75333c83
2 changed files with 3 additions and 24 deletions

View File

@ -94,27 +94,9 @@ uuid_parse_string (const gchar *str,
gint i, j, hi, lo;
guint expected_len = 36;
if (g_str_has_prefix (str, "urn:uuid:"))
str += 9;
else if (g_str_has_prefix (str, "{urn:uuid:"))
expected_len += 11;
else if (str[0] == '{')
expected_len += 2;
if (strlen (str) != expected_len)
return FALSE;
if (str[0] == '{')
{
if (str[expected_len - 1] != '}')
return FALSE;
str++;
}
if (g_str_has_prefix (str, "urn:uuid:"))
str += 9;
for (i = 0, j = 0; i < 16;)
{
if (j == 8 || j == 13 || j == 18 || j == 23)
@ -146,12 +128,9 @@ uuid_parse_string (const gchar *str,
*
* Parses the string @str and verify if it is a UUID.
*
* The function accepts the following syntaxes:
* The function accepts the following syntax:
*
* - simple forms (e.g. `f81d4fae-7dec-11d0-a765-00a0c91e6bf6`)
* - simple forms with curly braces (e.g.
* `{urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6}`)
* - URN (e.g. `urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6`)
*
* Note that hyphens are required within the UUID string itself,
* as per the aforementioned RFC.

View File

@ -30,13 +30,13 @@ test_guuid_string (void)
g_assert_false (g_uuid_string_is_valid ("00010203-0405-0607-0809"));
g_assert_false (g_uuid_string_is_valid ("zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz"));
g_assert_false (g_uuid_string_is_valid ("000102030405060708090a0b0c0d0e0f"));
g_assert_false (g_uuid_string_is_valid ("{urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6}"));
g_assert_false (g_uuid_string_is_valid ("urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6"));
g_assert_true (g_uuid_string_is_valid ("00010203-0405-0607-0809-0a0b0c0d0e0f"));
g_assert_true (g_uuid_string_is_valid ("7d444840-9dc0-11d1-b245-5ffdce74fad2"));
g_assert_true (g_uuid_string_is_valid ("e902893a-9d22-3c7e-a7b8-d6e313b71d9f"));
g_assert_true (g_uuid_string_is_valid ("6ba7b810-9dad-11d1-80b4-00c04fd430c8"));
g_assert_true (g_uuid_string_is_valid ("{urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6}"));
g_assert_true (g_uuid_string_is_valid ("urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6"));
}
static void