From 36db1e6e7cae6458344fe89a632752be384258e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemens=20B=C3=B6swirth?= Date: Fri, 20 Nov 2020 15:40:30 +0100 Subject: [PATCH] Implement new key name decision --- src/include/kdbprivate.h | 6 +- src/libs/elektra/keyname.c | 1167 ++++++++------------- src/libs/tools/src/backends.cpp | 18 +- src/libs/tools/src/plugins.cpp | 12 +- src/libs/tools/tests/testtool_backend.cpp | 95 +- src/plugins/augeas/augeas.c | 2 +- src/plugins/augeas/testmod_augeas.c | 8 +- src/plugins/yajl/yajl_gen.c | 10 +- src/plugins/yamlcpp/README.md | 2 +- tests/abi/testabi_key.c | 32 +- tests/abi/testabi_ks.c | 38 +- tests/ctest/test_backend.c | 137 ++- tests/ctest/test_globbing.c | 4 +- tests/ctest/test_internal.c | 46 +- tests/ctest/test_key.c | 23 +- tests/ctest/test_keyname.c | 986 +++++++++-------- tests/ctest/test_mount.c | 158 ++- tests/ctest/test_plugin.c | 22 +- tests/data/data_noescape.c | 1 - 19 files changed, 1275 insertions(+), 1492 deletions(-) diff --git a/src/include/kdbprivate.h b/src/include/kdbprivate.h index f6066d76825..4fb9da2d056 100644 --- a/src/include/kdbprivate.h +++ b/src/include/kdbprivate.h @@ -599,9 +599,9 @@ int keyIsUser (const Key * key); elektraNamespace elektraReadNamespace (const char * namespaceStr, size_t len); -int elektraKeyNameValidate (const char * name, const char * prefix, size_t * size, size_t * usize); -void elektraKeyNameCanonicalize (const char * name, char ** canonicalName, size_t canonicalSize, size_t offset); -void elektraKeyNameUnescape (const char * name, char ** unescapedName); +bool elektraKeyNameValidate (const char * name, bool isComplete); +void elektraKeyNameCanonicalize (const char * name, char ** canonicalName, size_t * canonicalSizePtr, size_t offset, size_t * usizePtr); +void elektraKeyNameUnescape (const char * name, char * unescapedName); size_t elektraKeyNameEscapePart (const char * part, char ** escapedPart); /* global plugin calls */ diff --git a/src/libs/elektra/keyname.c b/src/libs/elektra/keyname.c index 567923f519e..06de9e3c354 100644 --- a/src/libs/elektra/keyname.c +++ b/src/libs/elektra/keyname.c @@ -165,6 +165,45 @@ #include "kdbhelper.h" #include "kdbinternal.h" +/** + * Helper method: returns a pointer to the start of the last part of the given key name + * + * @param name a canonical key name + * @param len the length of the key name + */ +static char * findStartOfLastPart (char * name, size_t len) +{ + char * colon = strchr (name, ':'); + char * start = colon == NULL ? name : colon + 1; + ++start; // start after first slash + + char * cur = start + len - (start - name) - 1; + + if (cur == start) return NULL; // no base name + + while (cur >= start) + { + --cur; + while (cur >= start && *cur != '/') + { + --cur; + } + + size_t backslashes = 0; + while (cur - backslashes > start && *(cur - backslashes - 1) == '\\') + { + ++backslashes; + } + + if (backslashes % 2 == 0) + { + break; + } + } + + return cur < start - 1 ? NULL : cur; +} + /******************************************* * General name manipulation methods * @@ -403,10 +442,7 @@ ssize_t keySetName (Key * key, const char * newName) if (test_bit (key->flags, KEY_FLAG_RO_NAME)) return -1; if (newName == NULL || strlen (newName) == 0) return -1; - size_t oldKeySize = key->keySize; - size_t oldKeyUSize = key->keyUSize; - - if (!elektraKeyNameValidate (newName, NULL, &key->keySize, &key->keyUSize)) + if (!elektraKeyNameValidate (newName, true)) { // error invalid name return -1; @@ -424,32 +460,11 @@ ssize_t keySetName (Key * key, const char * newName) clear_bit (key->flags, (keyflag_t) KEY_FLAG_MMAP_KEY); } - if (key->keySize > oldKeySize) - { - // buffer growing -> realloc first - elektraRealloc ((void **) &key->key, key->keySize); - } + elektraKeyNameCanonicalize (newName, &key->key, &key->keySize, 0, &key->keyUSize); - if (key->keyUSize > oldKeyUSize) - { - // buffer growing -> realloc first - elektraRealloc ((void **) &key->ukey, key->keyUSize); - } - - elektraKeyNameCanonicalize (newName, &key->key, key->keySize, 0); - elektraKeyNameUnescape (key->key, &key->ukey); - - if (key->keySize < oldKeySize) - { - // buffer shrinking -> realloc after - elektraRealloc ((void **) &key->key, key->keySize); - } + elektraRealloc ((void **) &key->ukey, key->keyUSize); - if (key->keyUSize < oldKeyUSize) - { - // buffer shrinking -> realloc after - elektraRealloc ((void **) &key->ukey, key->keyUSize); - } + elektraKeyNameUnescape (key->key, key->ukey); set_bit (key->flags, KEY_FLAG_SYNC); @@ -457,662 +472,463 @@ ssize_t keySetName (Key * key, const char * newName) return key->keySize; } -int elektraKeyNameValidate (const char * name, const char * prefix, size_t * sizePtr, size_t * usizePtr) +/** + * Takes an escaped key name and validates it. + * Complete key names must inlcude a namespace or a leading slash. + * + * @param name The escaped key name to check + * @param isComplete Whether or not @p name is supposed to be a complete key name + * + * @retval #true If @p name is a valid key name. + * @retval #false Otherwise + * + * @ingroup keyname + */ +bool elektraKeyNameValidate (const char * name, bool isComplete) { - if (name == NULL || (strlen (name) == 0 && prefix == NULL)) return 0; - - size_t size = strlen (name) + 1; // +1 for terminator at end or separator at beginning - size_t usize = strlen (name) + 1; // +1 for terminator at end or separator at beginning + if (name == NULL || (strlen (name) == 0 && isComplete)) return 0; - if (prefix == NULL) + if (isComplete) { - if (*name != '/') + const char * colon = strchr (name, ':'); + if (colon != NULL) { - // check namespace - const char * colon = strchr (name, ':'); + if (elektraReadNamespace (name, colon - name - 1) == KEY_NS_NONE) + { + ELEKTRA_LOG_DEBUG ("Illegal namespace '%.*s': %s", (int) (colon - name - 1), name, name); + return 0; + } - if (colon == NULL) return 0; - if (elektraReadNamespace (name, colon - name - 1) == KEY_NS_NONE) return 0; + if (*(colon + 1) != '/') + { + ELEKTRA_LOG_DEBUG ("Missing slash after namespace: %s", name); + return 0; + } - usize -= colon - name; // unescaped namespace is always 1 long name = colon + 1; } - else + + if (*name != '/') { - ++usize; // unescaped namespace is always 1 long + ELEKTRA_LOG_DEBUG ("Illegal name start; expected (namespace +) slash: %s", name); + return 0; } - - if (*name != '/') return 0; - ++name; } - while (*name == '/') + const char * cur = name; + while ((cur = strchr (cur, '\\')) != NULL) { - // ignore additional leading slashes - ++name; - --size; - --usize; - } + ++cur; + switch (*cur) + { + case '\0': + ELEKTRA_LOG_DEBUG ("Dangling escape: %s", name); + return 0; + case '\\': + case '/': + ++cur; + // allowed anywhere + continue; + case '%': + if (*(cur - 2) == '/' && (*(cur + 1) == '/' || *(cur + 1) == '\0')) continue; - const char * pathStart = name; - size_t pathLen = strlen (pathStart); + break; + case '.': + if (*(cur - 2) == '/' && (*(cur + 1) == '/' || *(cur + 1) == '\0')) continue; + if (*(cur - 2) == '/' && *(cur + 1) == '.' && (*(cur + 2) == '/' || *(cur + 2) == '\0')) continue; - if (pathLen == 0) - { - if (prefix == NULL) - { - // root key (cascading or with namespace) - *sizePtr = size; - *usizePtr = usize; - return 1; + break; + case '#': { + const char * end = cur + 1; + while (isdigit (*end)) + { + ++end; + } + size_t len = end - cur; + + bool check1 = *end == '/' || *end == '\0'; + bool check2 = len < 20 || strncmp (cur + 1, "9223372036854775807", 19) <= 0; + bool check3 = *(cur + 1) != '0'; + + if (check1 && check2 && check3) continue; + + break; } - else - { - // nothing to add - return 1; } - } - // need to validate path in reverse because of /../ parts - name = pathStart + pathLen - 1; - // check backslashes at end of name - // this ONLY checks for dangling escapes, size adjustments are done in the main loop - size_t backslashes = 0; - while (name - backslashes >= pathStart && *(name - backslashes) == '\\') - { - ++backslashes; + ELEKTRA_LOG_DEBUG ("Illegal escape '\\%c': %s", *cur, name); + return 0; } - if (backslashes % 2 != 0) + return 1; +} + +/** + * Takes a valid (non-)canonical key name and produces its canonical form. + * As a side-effect it can also calculate the size of the corresponding unescaped key name. + * + * @param name The key name that is processed + * @param canonicalName Output buffer for the canonical name + * @param canonicalSizePtr Pointer to size of @p canonicalName + * @param offset Offset into @p canonicalName + * @param usizePtr Output variable for the size of the unescaped name + * + * @pre @p name MUST be a valid (non-)canonical key name. If it is not, the result is undefined + * @pre @p canonicalName MUST be a valid first argument for elektraRealloc() when cast to void** + * @pre @p canonicalSizePtr >= @p offset + * @pre @p offset MUST be 0 or `*canonicalName + offset` MUST point to the zero-termintor of a valid canonical key name that starts at + * `*canonicalName` + * @pre if @p offset is 0 then `*usizePtr` MUST 0, otherwise `*usizePtr` MUST be the correct unescaped size of the existing canonical name + * in `*canonicalName` + * + * @see elektraKeyNameValidate + * + * @ingroup keyname + */ +void elektraKeyNameCanonicalize (const char * name, char ** canonicalName, size_t * canonicalSizePtr, size_t offset, size_t * usizePtr) +{ + size_t nameLen = strlen (name) + 1; + + // ensure output is at least as big as input + // output buffer will be enlarged when needed + // at the end we shrink to the correct size + if (offset + nameLen + 1 > *canonicalSizePtr) { - // dangling escape - return 0; + *canonicalSizePtr = offset + nameLen; + elektraRealloc ((void **) canonicalName, *canonicalSizePtr); } - enum - { - PART_END, - DIGITS, - UNDERSCORES, - OTHER - } state = PART_END; - - char prev = '\0'; - size_t partLen = 0; - size_t digits = 0; - size_t underscores = 0; - size_t skip = 0; - while (name >= pathStart) + char * outPtr; + size_t usize; + + // stores start of first part + size_t rootOffset; + if (offset == 0) { - size_t trailingSlashes = 0; - if (state == PART_END) - { - // count trailing slashes (the last one might be escaped) - while (name - trailingSlashes >= pathStart && *(name - trailingSlashes) == '/') - { - ++trailingSlashes; - } - } + // namespace byte + usize = 1; + outPtr = *canonicalName; - // count upcomming backslashes - backslashes = 0; - size_t backslashOffset = trailingSlashes == 0 ? 1 : trailingSlashes; - while (name - backslashOffset - backslashes >= pathStart && *(name - backslashOffset - backslashes) == '\\') + if (*name != '/') { - ++backslashes; - } - - int escaped = backslashes % 2 != 0; + // find end of namespace + const char * colon = strchr (name, ':'); - // the last trailing slash is actually escaped - if (trailingSlashes > 0 && escaped) - { - --trailingSlashes; + // copy namespace + memcpy (outPtr, name, colon - name + 1); + outPtr += colon - name + 1; + name = colon + 1; } - name -= trailingSlashes; - size -= trailingSlashes; - usize -= trailingSlashes; + rootOffset = outPtr - *canonicalName; - char cur = *name; + // handle root slash + *outPtr++ = '/'; + usize += 1; + } + else + { + usize = *usizePtr; + outPtr = *canonicalName + offset - 2; - switch (state) + if (usize == 3) { - case PART_END: - if (isdigit (cur)) - { - digits = 1; - partLen = 1; - state = DIGITS; - } - else - { - partLen = 1; - state = OTHER; - } - break; - case DIGITS: - if (isdigit (cur)) - { - ++digits; - } - else - { - if (cur == '_') - { - underscores = 1; - state = UNDERSCORES; - } - else - { - state = OTHER; - } - } - break; - case UNDERSCORES: - if (cur == '_') - { - ++underscores; - state = UNDERSCORES; - } - else - { - state = OTHER; - } - break; - case OTHER: - digits = 0; - underscores = 0; - break; + // root key -> re-use trailing slash + --usize; + ++outPtr; } - - // move past cur - --name; - - // move past upcomming backslashes - name -= backslashes; - if (skip == 0) + else { - usize -= backslashes / 2; + // not root key -> add trailing slash + *++outPtr = '/'; + ++outPtr; } - partLen += backslashes; - if (escaped) + // find root slash + if (**canonicalName == '/') { - if (skip == 0) - { - --usize; - } - - // uneven number of backslashes -> check escape sequence - if (backslashes == 1 && (name < pathStart || *name == '/')) - { - if (cur != '\\' && cur != '/' && cur != '.' && cur != '#' && cur != '%' && cur != '@') - { - // illegal escape sequence (at start of part) - return 0; - } - } - else - { - if (cur != '\\' && cur != '/') - { - // illegal escape sequence (in middle of part) - return 0; - } - } + rootOffset = 0; } - else if (backslashes > 0) + else { - // even number of backslashes -> cur is '\\' after moving past backslashes - cur = '\\'; + rootOffset = strchr (*canonicalName, ':') - *canonicalName + 1; } + } - int partStart = 0; - if (name < pathStart || *name == '/') + while (*name != '\0') + { + // STATE: name -- on part separator or first char of part + // outPtr -- start of new part + // usize -- namespace + separator + previous parts + separator + // -> skip part separator + if (*name == '/') { - size_t count = 0; - while (name - 1 - count >= pathStart && *(name - 1 - count) == '\\') - { - ++count; - } + ++name; + } - if (count % 2 == 0) - { - partStart = 1; - } + // STATE: name -- first char of part + // outPtr -- start of new part + // usize -- namespace + separator + previous parts + separator + // -> skip all leading slashes ... + while (*name == '/') + { + ++name; } - if (state != PART_END && partStart) + // ... then check for special part + switch (*name) { - // reached start of part, cur is first char in part, name points to char left of cur starting the part - // escaped indicates whether cur is escaped - int isSkip = 0; - if (!escaped) + case '\0': + // STATE: name -- end of string + // outPtr -- trailing slash + // usize -- namespace + separator + previous parts + separator + // -> next iteration: loop will end, trailing slash will be replaced with terminator + continue; + case '.': + switch (*(name + 1)) { - switch (cur) + case '/': + case '\0': + // dot-part -> skip + ++name; + // STATE: name -- part separator + // outPtr -- trailing slash + // usize -- namespace + separator + previous parts + separator + // -> next iteration: trailing slash will be overwritten + continue; + case '.': + if (*(name + 2) == '/' || *(name + 2) == '\0') { - case '#': - if (partLen == 1) break; + // dot-dot-part -> go back one part - if (digits == 0 || (underscores > 0 && underscores != digits - 1) || digits > 19 || - (digits == 19 && strncmp (&name[2 + underscores], "9223372036854775807", 19) > 0) || - (name[2 + underscores] == '0' && digits != 1)) - { - // invalid array part - return 0; - } + // 1. terminate outPtr so that findStartOfLastPart works + *outPtr = '\0'; - if (skip == 0) - { - // account for potentially missing underscores - size += (digits - 1) - underscores; // digits - 1 or 0 - usize += (digits - 1) - underscores; // digits - 1 or 0 - } + // 2. find start of previous part + char * newOutPtr = findStartOfLastPart (*canonicalName, outPtr - *canonicalName); + + // 3. calculate unescaped length of part, including separator + size_t ulen = outPtr - newOutPtr - 1; - break; - case '%': - if (partLen == 1 && skip == 0) + // 4. adjust pointers + name += 2; + outPtr = newOutPtr + 1; + + // 5. if previous part is empty ('%') ... + if (ulen == 2 && *newOutPtr + 1 == '%') { - --usize; + // 5a. ... then adjust len + ulen = 1; } - break; - case '@': - // reserved - return 0; - case '.': - if (partLen == 1 && skip == 0) + else { - // part was '/./' - --size; - --usize; - - if (usize > 3 || prefix != NULL) + // 5b. ... else account of backslahes + size_t backslashes = 0; + for (size_t i = 1; i + 1 < ulen; ++i) { - --size; - --usize; + if (*(newOutPtr + i) == '\\') + { + ++backslashes; + } } + ulen -= (backslashes + 1) / 2; } - else if (partLen == 2 && prev == '.') - { - // part was '/../' - // size updated below - isSkip = 1; - } - break; - default: - break; - } - } - if (name >= pathStart) - { - // move past slash - --name; - } - - if (skip > 0 || isSkip) - { - // subtract part - size -= partLen; - usize -= partLen; + // 6. adjust usize + ELEKTRA_ASSERT (ulen <= usize - 2, "usize underflow"); + usize -= ulen; - if (usize > 3 || prefix != NULL) - { - // subtract slash - --size; - --usize; - } - - if (!isSkip) - { - // finished skipping a part - --skip; + // STATE: name -- part separator + // outPtr -- start of this part + // usize -- namespace + separator + parts before previous part + separator + // -> next iteration: part will be overwritten + continue; } + break; } + break; + case '%': + if (*(name + 1) == '/' || *(name + 1) == '\0') + { + // empty part -> copy but only count / in usize + ++name; + *outPtr++ = '%'; + *outPtr++ = '/'; + usize++; - if (isSkip) + // STATE: name -- on part separator or end of string + // outPtr -- after last part + // usize -- namespace + separator + previous parts + separator + (empty part) + separator + continue; + } + break; + case '#': { + // find end of digits + const char * end = name + 1; + while (isdigit (*end)) { - ++skip; + ++end; } + size_t len = end - name - 1; - digits = 0; - underscores = 0; + bool check1 = *end == '/' || *end == '\0'; + bool check2 = *(name + 1) != '0'; - state = PART_END; + if (len > 0 && check1 && check2 && (len < 19 || (len == 19 && strncmp (name + 1, "9223372036854775807", 19) <= 0))) + { + // non-canonical array part -> add underscores + + // but first update buffer + size_t pos = outPtr - *canonicalName; + + *canonicalSizePtr += offset + len - 1; + elektraRealloc ((void **) canonicalName, *canonicalSizePtr); + outPtr = *canonicalName + pos; + + *outPtr = '#'; + memset (outPtr + 1, '_', len - 1); + memcpy (outPtr + len, name + 1, len); + outPtr += 2 * len; + *outPtr++ = '/'; + usize += 2 * len + 1; + name = end; + + // STATE: name -- part separator + // outPtr -- after this part + // usize -- namespace + separator + previous parts + separator + current part + separator + // -> next iteration: new part will be started + continue; + } + break; + } } - ++partLen; - prev = cur; - } - - if (prefix == NULL) - { - if (skip > 0) return 0; // too many .. parts - } - else - { - size_t psize = *sizePtr; - size_t pusize = *usizePtr; - - if (skip > 0) + // STATE: name -- first char of non-special part + // outPtr -- start of new part + // usize -- previous parts + separator + // -> find end of part + const char * end = name; + while (*end != '\0') { - // some .. parts left to handle - while (skip > 0) + size_t backslashes = 0; + while (*end == '\\') { - // still some .. parts left to handle - do - { - // subtract slash - --psize; - --pusize; - - if (pusize < 3) return 0; // reached namespace - - while (pusize >= 3 && prefix[psize - 1] != '/') - { - --psize; - --pusize; - } - } while (pusize >= 3 && prefix[psize - 2] == '\\'); - - --skip; + ++backslashes; + ++end; } - if (pusize == 2) + usize += backslashes / 2; + if (*end == '\0' || (*end == '/' && backslashes % 2 == 0)) { - // re-add terminator - ++psize; - ++pusize; + break; } - } - if (pusize == 3 && size > 0) - { - // namespace root key already has slash at end - --psize; - --pusize; + ++end; + usize += 1; } - size += psize; - usize += pusize; - } + size_t len = end - name; - *sizePtr = size; - *usizePtr = usize; - return 1; -} - -// assume name is validated with elektraKeyNameValidate, otherwise behaviour undef -// return size including zero terminator -> 0 is error -void elektraKeyNameCanonicalize (const char * name, char ** canonicalName, size_t canonicalSize, size_t offset) -{ - // TODO (kodebach): check and document - char * cname = *canonicalName + offset; - char * outPtr = cname; - - if (offset == 0) - { - if (name[0] != '/') - { - // handle namespace - const char * colonSlash = strstr (name, ":/"); - size_t len = colonSlash - name; - memcpy (outPtr, name, len); - outPtr += len; - *outPtr++ = ':'; - name = colonSlash + 1; - } + // STATE: name -- start of part + // end -- end of part + // outPtr -- start of new part + // usize -- previous parts + separator + current part + // -> copy part + part separator + memcpy (outPtr, name, len); + outPtr += len; *outPtr++ = '/'; - ++name; + usize += 1; + name += len; + + // STATE: name -- on part separator or end of string + // outPtr -- after last part + // usize -- namespace + separator + previous parts + separator + current part + separator } - while (*name == '/') + // terminate + if (outPtr > *canonicalName + rootOffset + 1) { - // ignore additional leading slashes - ++name; + // not a root key -> need to replace trailing slash + --outPtr; } - - const char * pathStart = name; - size_t pathLen = strlen (pathStart); - - if (pathLen == 0) + else if (offset == 0 || usize == 2) { - // no path -> just terminate - *outPtr = '\0'; - return; + // root key -> don't replace slash, need to adjust usize + ++usize; } - - // canonicalize path in reverse because of .. - name = pathStart + pathLen - 1; - outPtr = *canonicalName + canonicalSize - 1; - - // terminate *outPtr = '\0'; - enum - { - PART_END, - DIGITS, - UNDERSCORES, - OTHER - } state = PART_END; - - char prev = '\0'; - size_t skip = 0; - size_t digits = 0; - size_t underscores = 0; - size_t partLen = 0; - while (name >= pathStart) - { - char cur = *name; - - // count upcomming backslashes - size_t backslashes = 0; - while (name - 1 - backslashes >= pathStart && *(name - 1 - backslashes) == '\\') - { - ++backslashes; - } + // output size and shrink buffer + *canonicalSizePtr = outPtr - *canonicalName + 1; + elektraRealloc ((void **) canonicalName, *canonicalSizePtr); - int escaped = backslashes % 2 != 0; - - switch (state) - { - case PART_END: - if (isdigit (cur)) - { - digits = 1; - partLen = 1; - state = DIGITS; - } - else if (cur != '/' || escaped) - { - partLen = 1; - state = OTHER; - } - break; - case DIGITS: - if (isdigit (cur)) - { - ++digits; - } - else - { - if (cur == '_') - { - underscores = 1; - state = UNDERSCORES; - } - else - { - state = OTHER; - } - } - break; - case UNDERSCORES: - if (cur == '_') - { - ++underscores; - state = UNDERSCORES; - } - else - { - state = OTHER; - } - break; - case OTHER: - digits = 0; - underscores = 0; - break; - } - - // move past cur - --name; - - if (state != PART_END && (name < pathStart || (*name == '/' && *(name - 1) != '\\'))) - { - // reached start of part, cur is first char in part, name points to char left of cur starting the part - int isSkip = 0; - switch (cur) - { - case '#': - if (skip == 0) - { - if (digits > 0) - { - outPtr -= digits; - memcpy (outPtr, name + 2 + underscores, digits); - outPtr -= digits - 1; - memset (outPtr, '_', digits - 1); - } - *--outPtr = '#'; - *--outPtr = '/'; - } - break; - case '.': - if (partLen == 1) - { - // part was '/./' -> ignored - } - else if (partLen == 2 && prev == '.') - { - // part was '/../' - isSkip = 1; - } - else if (skip == 0) - { - // other part starting with . - outPtr -= partLen; - memcpy (outPtr, name + 1, partLen); - *--outPtr = '/'; - } - break; - default: - if (skip == 0) - { - outPtr -= partLen; - memcpy (outPtr, name + 1, partLen); - *--outPtr = '/'; - } - break; - } - - if (name >= pathStart) - { - // move past slash - --name; - } - - if (skip > 0 && !isSkip) - { - // finished skipping a part - --skip; - } - - if (isSkip) - { - ++skip; - } - - digits = 0; - underscores = 0; - - state = PART_END; - } - - ++partLen; - prev = cur; + // output unescape size if requested + if (usizePtr != NULL) + { + *usizePtr = usize; } } -// assumes name is canonical -void elektraKeyNameUnescape (const char * canonicalName, char ** unescapedName) +/** + * Takes a canonical key name and unescapes it. + * + * @param canonicalName The canonical name to unescape + * @param unescapedName Output buffer for the unescaped name + * + * @pre @p canonicalName MUST be a canonical key name. If this is not the case, the result is undefined. + * @pre @p unescapedName MUST be allocated to the correct size. + * + * @see elektraKeyNameCanonicalize + * + * @ingroup keyname + */ +void elektraKeyNameUnescape (const char * canonicalName, char * unescapedName) { - // TODO (kodebach): check and document - - char * uname = *unescapedName; - char * outPtr = uname; - - const char * lastSpecial = canonicalName; + char * outPtr = unescapedName; if (canonicalName[0] != '/') { - const char * colonSlash = strstr (canonicalName, ":/"); - *outPtr++ = elektraReadNamespace (canonicalName, colonSlash - canonicalName); - lastSpecial = colonSlash + 1; + // translate namespace + const char * colon = strchr (canonicalName, ':'); + *outPtr++ = elektraReadNamespace (canonicalName, colon - canonicalName); + canonicalName = colon + 1; } else { + // set cascading namespace *outPtr++ = KEY_NS_CASCADING; } - - // copy piecewise between special characters - const char * nextSpecial; - while ((nextSpecial = strpbrk (lastSpecial, "%\\")) != NULL) + while (*canonicalName != '\0') { - // copy stuff before special - if (nextSpecial > lastSpecial) + switch (*canonicalName) { - size_t len = nextSpecial - lastSpecial; - memcpy (outPtr, lastSpecial, len); + case '\\': + // escape sequence: skip backslash ... + ++canonicalName; - // replace / with \0 - for (size_t i = 0; i < len; ++i, ++outPtr) - { - if (*outPtr == '/') - { - *outPtr = '\0'; - } - } - } + // ... and output escaped char + *outPtr++ = *canonicalName; + ++canonicalName; + break; + case '/': + // new part: output zero-byte part separator and ... + *outPtr++ = '\0'; + ++canonicalName; - if (*nextSpecial == '\\') - { - *outPtr++ = *++nextSpecial; - } - else if (*nextSpecial == '%') - { - if (*(nextSpecial - 1) != '/' || (*(nextSpecial + 1) != '/' && *(nextSpecial + 1) != '\0')) + // ... check for empty part + if (*canonicalName == '%' && (*(canonicalName + 1) == '/' || *(canonicalName + 1) == '\0')) { - *outPtr++ = '%'; + // skip percent + ++canonicalName; } - } - - lastSpecial = nextSpecial + 1; - } - - // copy rest of name - size_t len = strlen (lastSpecial); - memcpy (outPtr, lastSpecial, len); - - // replace / with \0 - for (size_t i = 0; i < len; ++i, ++outPtr) - { - if (*outPtr == '/') - { - *outPtr = '\0'; + break; + default: + // nothing special, just output + *outPtr++ = *canonicalName; + ++canonicalName; + break; } } @@ -1236,69 +1052,83 @@ ssize_t keyGetBaseName (const Key * key, char * returned, size_t maxSize) return baseSize; } +/** + * Takes a single key name part and produces its escaped form. + * + * @param part A single key name part, i.e. contained '/' will be escaped, '\0' terminates part + * @param escapedPart Output buffer for the escaped form + * + * @pre @p escapedPart MUST be a valid first argument for elektraRealloc() when cast to `void**` + * + * @returns The size of the escaped form excluding the zero terminator + */ size_t elektraKeyNameEscapePart (const char * part, char ** escapedPart) { if (!part) return 0; size_t partLen = strlen (part); + + // first check for special parts if (partLen == 0) { - elektraRealloc ((void **) escapedPart, 2); - **escapedPart = '%'; - *(*escapedPart + 1) = '\0'; + // actually empty part + *escapedPart = elektraStrDup ("%"); return 1; } - if (partLen == 1 && part[0] == '.') + switch (part[0]) { - elektraRealloc ((void **) escapedPart, 3); - **escapedPart = '\\'; - *(*escapedPart + 1) = '.'; - *(*escapedPart + 2) = '\0'; - return 2; - } - - if (partLen == 2 && part[0] == '.' && part[1] == '.') - { - elektraRealloc ((void **) escapedPart, 4); - **escapedPart = '\\'; - *(*escapedPart + 1) = '.'; - *(*escapedPart + 2) = '.'; - *(*escapedPart + 3) = '\0'; - return 3; - } - - if (part[0] == '#' && partLen != 1) - { - size_t underscores = 0; - while (part[1 + underscores] == '_') + case '%': + if (partLen == 1) { - ++underscores; + // escaped empty part + *escapedPart = elektraStrDup ("\\%"); + return 2; } - - size_t digits = 0; - while (isdigit (part[1 + underscores + digits])) + break; + case '.': + switch (part[1]) { - ++digits; + case '\0': + // dot part + *escapedPart = elektraStrDup ("\\."); + return 2; + case '.': + if (partLen == 2) + { + // dot-dot part + *escapedPart = elektraStrDup ("\\.."); + return 3; + } + break; } - - if (partLen != 1 + underscores + digits || digits == 0 || underscores != digits - 1 || digits > 19 || - (digits == 19 && strncmp (&part[1 + underscores], "9223372036854775807", 19) > 0) || - (part[1 + underscores] == '0' && digits > 1)) + break; + case '#': + if (partLen > 1) { - // not a correct array part -> need to escape - elektraRealloc ((void **) escapedPart, partLen + 2); - **escapedPart = '\\'; - memcpy (*escapedPart + 1, part, partLen); - *(*escapedPart + partLen + 1) = '\0'; - return partLen + 1; + // possibly (non-)canonical array part + size_t digits = 0; + while (isdigit (part[1 + digits])) + { + ++digits; + } + + if (digits > 1 && part[1] != '0' && + (digits < 19 || (digits == 19 && strncmp (&part[1], "9223372036854775807", 19) <= 0))) + { + // non-canonical array part -> need to escape + elektraRealloc ((void **) escapedPart, partLen + 2); + **escapedPart = '\\'; + memcpy (*escapedPart + 1, part, partLen + 1); + return partLen + 1; + } } + break; } - int specialStart = strchr ("%@/\\", part[0]) != NULL; - size_t special = specialStart ? 1 : 0; - - const char * cur = part + 1; + // not a special part -> just escape backslash and slash + size_t special = 0; + const char * cur = part; while ((cur = strpbrk (cur, "/\\")) != NULL) { ++special; @@ -1307,36 +1137,19 @@ size_t elektraKeyNameEscapePart (const char * part, char ** escapedPart) elektraRealloc ((void **) escapedPart, partLen + special + 1); + cur = part; char * outPtr = *escapedPart; - - if (specialStart) - { - *outPtr++ = '\\'; - } - - const char * last = part; - while ((cur = strpbrk (last, "/\\")) != NULL) + while (*cur != '\0') { - size_t len = cur - last; - memcpy (outPtr, last, len); - outPtr += len; - - if (cur > part) + if (*cur == '/' || *cur == '\\') { - // start backslash already added above *outPtr++ = '\\'; } - *outPtr++ = *cur; - - last = cur + 1; + *outPtr++ = *cur++; } + *outPtr = '\0'; - size_t len = strlen (last); - memcpy (outPtr, last, len); - outPtr += len; - *outPtr++ = '\0'; - - return outPtr - *escapedPart - 1; + return outPtr - *escapedPart; } static size_t keyAddBaseNameInternal (Key * key, const char * baseName) @@ -1537,10 +1350,7 @@ ssize_t keyAddName (Key * key, const char * newName) if (strlen (newName) == 0) return key->keySize; - size_t oldKeySize = key->keySize; - size_t oldKeyUSize = key->keyUSize; - - if (!elektraKeyNameValidate (newName, key->key, &key->keySize, &key->keyUSize)) + if (!elektraKeyNameValidate (newName, false)) { // error invalid name suffix return -1; @@ -1562,71 +1372,16 @@ ssize_t keyAddName (Key * key, const char * newName) clear_bit (key->flags, (keyflag_t) KEY_FLAG_MMAP_KEY); } - if (key->keySize > oldKeySize) - { - // buffer growing -> realloc first - elektraRealloc ((void **) &key->key, key->keySize); - } + elektraKeyNameCanonicalize (newName, &key->key, &key->keySize, key->keySize, &key->keyUSize); - if (key->keyUSize > oldKeyUSize) - { - // buffer growing -> realloc first - elektraRealloc ((void **) &key->ukey, key->keyUSize); - } + elektraRealloc ((void **) &key->ukey, key->keyUSize); - elektraKeyNameCanonicalize (newName, &key->key, key->keySize, oldKeySize); - elektraKeyNameUnescape (key->key, &key->ukey); - - if (key->keySize < oldKeySize) - { - // buffer shrinking -> realloc after - elektraRealloc ((void **) &key->key, key->keySize); - } - - if (key->keyUSize < oldKeyUSize) - { - // buffer shrinking -> realloc after - elektraRealloc ((void **) &key->ukey, key->keyUSize); - } + elektraKeyNameUnescape (key->key, key->ukey); set_bit (key->flags, KEY_FLAG_SYNC); return key->keySize; } -static const char * elektraKeyFindBaseNamePtr (Key * key) -{ - // TODO (kodebach): document - const char * colon = strchr (key->key, ':'); - const char * start = colon == NULL ? key->key : colon + 1; - ++start; // start after first slash - - const char * cur = start + key->keySize - (start - key->key) - 1; - - if (cur == start) return NULL; // no base name - - while (cur >= start) - { - --cur; - while (cur >= start && *cur != '/') - { - --cur; - } - - size_t backslashes = 0; - while (cur - backslashes > start && *(cur - backslashes - 1) == '\\') - { - ++backslashes; - } - - if (backslashes % 2 == 0) - { - break; - } - } - - return cur < start - 1 ? NULL : cur; -} - /** * Sets @c baseName as the new basename for @c key. * @@ -1681,7 +1436,7 @@ ssize_t keySetBaseName (Key * key, const char * baseName) if (!key->key) return -1; // adjust sizes to exclude base name - const char * baseNamePtr = elektraKeyFindBaseNamePtr (key); + const char * baseNamePtr = findStartOfLastPart (key->key, key->keySize); if (baseNamePtr == NULL) { return -1; diff --git a/src/libs/tools/src/backends.cpp b/src/libs/tools/src/backends.cpp index 7d02a7f33bc..f6ddd10a8ce 100644 --- a/src/libs/tools/src/backends.cpp +++ b/src/libs/tools/src/backends.cpp @@ -145,20 +145,10 @@ bool Backends::umount (std::string const & mountPath, KeySet & mountConf) */ std::string Backends::getBasePath (std::string mp) { - if (mp[0] == '/') - { - Key k (Backends::mountpointsPath, KEY_END); - Key kmp (mp, KEY_END); // canonify name - k.addBaseName (kmp.getName ()); // escape name - return k.getName (); - } - else - { - Key k (Backends::mountpointsPath, KEY_END); - Key kmp ("/" + mp, KEY_END); // canonify name - k.addBaseName (kmp.getName ().substr (1)); // escape name - return k.getName (); - } + Key k (Backends::mountpointsPath, KEY_END); + Key kmp (mp, KEY_END); // canonify name + k.addBaseName (kmp.getName ()); // escape name + return k.getName (); } /** diff --git a/src/libs/tools/src/plugins.cpp b/src/libs/tools/src/plugins.cpp index eb632eafa62..4efb6154d4b 100644 --- a/src/libs/tools/src/plugins.cpp +++ b/src/libs/tools/src/plugins.cpp @@ -428,8 +428,8 @@ void ErrorPlugins::serialise (Key & baseKey, KeySet & ret) bool fr = plugins[i]->firstRef; std::ostringstream pluginNumber; - pluginNumber << i; - std::string name = baseKey.getName () + "/errorplugins/\\#" + pluginNumber.str () + plugins[i]->refname (); + pluginNumber << (i < 10 ? "#" : "\\#") << i; + std::string name = baseKey.getName () + "/errorplugins/" + pluginNumber.str () + plugins[i]->refname (); ret.append (*Key (name, KEY_COMMENT, "A plugin", KEY_END)); if (fr) serializeConfig (name, plugins[i]->getConfig (), ret); } @@ -445,8 +445,8 @@ void GetPlugins::serialise (Key & baseKey, KeySet & ret) bool fr = plugins[i]->firstRef; std::ostringstream pluginNumber; - pluginNumber << i; - std::string name = baseKey.getName () + "/getplugins/\\#" + pluginNumber.str () + plugins[i]->refname (); + pluginNumber << (i < 10 ? "#" : "\\#") << i; + std::string name = baseKey.getName () + "/getplugins/" + pluginNumber.str () + plugins[i]->refname (); ret.append (*Key (name, KEY_COMMENT, "A plugin", KEY_END)); if (fr) serializeConfig (name, plugins[i]->getConfig (), ret); } @@ -463,8 +463,8 @@ void SetPlugins::serialise (Key & baseKey, KeySet & ret) bool fr = plugins[i]->firstRef; std::ostringstream pluginNumber; - pluginNumber << i; - std::string name = baseKey.getName () + "/setplugins/\\#" + pluginNumber.str () + plugins[i]->refname (); + pluginNumber << (i < 10 ? "#" : "\\#") << i; + std::string name = baseKey.getName () + "/setplugins/" + pluginNumber.str () + plugins[i]->refname (); ret.append (*Key (name, KEY_COMMENT, "A plugin", KEY_END)); if (fr) serializeConfig (name, plugins[i]->getConfig (), ret); } diff --git a/src/libs/tools/tests/testtool_backend.cpp b/src/libs/tools/tests/testtool_backend.cpp index 4592fece2e2..18134fce84a 100644 --- a/src/libs/tools/tests/testtool_backend.cpp +++ b/src/libs/tools/tests/testtool_backend.cpp @@ -99,19 +99,18 @@ TEST (Backend, SimpleBackend) EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\//errorplugins") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/\\//errorplugins/\\#5#" KDB_DEFAULT_RESOLVER "#resolver#") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\//errorplugins/#5#" KDB_DEFAULT_RESOLVER "#resolver#") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\//getplugins") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\//getplugins/\\#0#resolver") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\//getplugins/#0#resolver") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\//getplugins/\\#5#dump#dump#") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\//getplugins/#5#dump#dump#") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); @@ -121,15 +120,15 @@ TEST (Backend, SimpleBackend) EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\//setplugins") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\//setplugins/\\#0#resolver") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\//setplugins/#0#resolver") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\//setplugins/\\#5#dump") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\//setplugins/#5#dump") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\//setplugins/\\#7#resolver") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\//setplugins/#7#resolver") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; } @@ -174,7 +173,7 @@ TEST (Backend, CrazyName) EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/\\/crazy\\/a..__.b\\/._.\\/._c__d/errorplugins/\\#5#" KDB_DEFAULT_RESOLVER "#resolver#") + "system:/elektra/mountpoints/\\/crazy\\/a..__.b\\/._.\\/._c__d/errorplugins/#5#" KDB_DEFAULT_RESOLVER "#resolver#") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); @@ -183,12 +182,12 @@ TEST (Backend, CrazyName) EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/\\/crazy\\/a..__.b\\/._.\\/._c__d/getplugins/\\#0#resolver") + "system:/elektra/mountpoints/\\/crazy\\/a..__.b\\/._.\\/._c__d/getplugins/#0#resolver") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/\\/crazy\\/a..__.b\\/._.\\/._c__d/getplugins/\\#5#dump#dump#") + "system:/elektra/mountpoints/\\/crazy\\/a..__.b\\/._.\\/._c__d/getplugins/#5#dump#dump#") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); @@ -201,16 +200,16 @@ TEST (Backend, CrazyName) EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/\\/crazy\\/a..__.b\\/._.\\/._c__d/setplugins/\\#0#resolver") + "system:/elektra/mountpoints/\\/crazy\\/a..__.b\\/._.\\/._c__d/setplugins/#0#resolver") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\/crazy\\/a..__.b\\/._.\\/._c__d/setplugins/\\#5#dump") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/\\/crazy\\/a..__.b\\/._.\\/._c__d/setplugins/#5#dump") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/\\/crazy\\/a..__.b\\/._.\\/._c__d/setplugins/\\#7#resolver") + "system:/elektra/mountpoints/\\/crazy\\/a..__.b\\/._.\\/._c__d/setplugins/#7#resolver") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; } @@ -270,23 +269,22 @@ TEST (Backend, SimpleBackendWithConf) EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/\\#5#" KDB_DEFAULT_RESOLVER "#resolver#") + "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/#5#" KDB_DEFAULT_RESOLVER "#resolver#") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/\\#5#" KDB_DEFAULT_RESOLVER "#resolver#/config") + "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/#5#" KDB_DEFAULT_RESOLVER "#resolver#/config") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/\\#5#" KDB_DEFAULT_RESOLVER - "#resolver#/config/other_res_conf") + "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/#5#" KDB_DEFAULT_RESOLVER "#resolver#/config/other_res_conf") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "do resolving too") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/\\#5#" KDB_DEFAULT_RESOLVER "#resolver#/config/res_conf") + "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/#5#" KDB_DEFAULT_RESOLVER "#resolver#/config/res_conf") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "do resolving") << "string of element in keyset wrong"; mountConfig.next (); @@ -294,25 +292,25 @@ TEST (Backend, SimpleBackendWithConf) << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/\\#0#resolver") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/#0#resolver") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/\\#5#dump#dump#") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/#5#dump#dump#") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/\\#5#dump#dump#/config") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/#5#dump#dump#/config") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/getplugins/\\#5#dump#dump#/config/file_format") + "system:/elektra/mountpoints/user:\\/somewhere/getplugins/#5#dump#dump#/config/file_format") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "1") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/getplugins/\\#5#dump#dump#/config/other_dump_conf") + "system:/elektra/mountpoints/user:\\/somewhere/getplugins/#5#dump#dump#/config/other_dump_conf") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "some dump config") << "string of element in keyset wrong"; mountConfig.next (); @@ -324,15 +322,15 @@ TEST (Backend, SimpleBackendWithConf) << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/\\#0#resolver") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/#0#resolver") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/\\#5#dump") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/#5#dump") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/\\#7#resolver") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/#7#resolver") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; } @@ -425,23 +423,22 @@ TEST (Backend, SimpleBackendWithNeededConf) EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/\\#5#" KDB_DEFAULT_RESOLVER "#resolver#") + "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/#5#" KDB_DEFAULT_RESOLVER "#resolver#") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/\\#5#" KDB_DEFAULT_RESOLVER "#resolver#/config") + "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/#5#" KDB_DEFAULT_RESOLVER "#resolver#/config") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/\\#5#" KDB_DEFAULT_RESOLVER - "#resolver#/config/other_res_conf") + "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/#5#" KDB_DEFAULT_RESOLVER "#resolver#/config/other_res_conf") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "do resolving too") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/\\#5#" KDB_DEFAULT_RESOLVER "#resolver#/config/res_conf") + "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/#5#" KDB_DEFAULT_RESOLVER "#resolver#/config/res_conf") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "do resolving") << "string of element in keyset wrong"; mountConfig.next (); @@ -449,25 +446,25 @@ TEST (Backend, SimpleBackendWithNeededConf) << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/\\#0#resolver") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/#0#resolver") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/\\#5#fstab#fstab#") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/#5#fstab#fstab#") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/\\#5#fstab#fstab#/config") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/#5#fstab#fstab#/config") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/getplugins/\\#5#fstab#fstab#/config/file_format") + "system:/elektra/mountpoints/user:\\/somewhere/getplugins/#5#fstab#fstab#/config/file_format") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "1") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/getplugins/\\#5#fstab#fstab#/config/other_dump_conf") + "system:/elektra/mountpoints/user:\\/somewhere/getplugins/#5#fstab#fstab#/config/other_dump_conf") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "some dump config") << "string of element in keyset wrong"; mountConfig.next (); @@ -479,15 +476,15 @@ TEST (Backend, SimpleBackendWithNeededConf) << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/\\#0#resolver") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/#0#resolver") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/\\#5#fstab") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/#5#fstab") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/\\#7#resolver") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/#7#resolver") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; } @@ -549,17 +546,17 @@ TEST (Backend, SimpleBackendWithUnderscore) EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/\\#5#resolver_fm_b_b#resolver_fm_b_b#") + "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/#5#resolver_fm_b_b#resolver_fm_b_b#") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/\\#5#resolver_fm_b_b#resolver_fm_b_b#/config") + "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/#5#resolver_fm_b_b#resolver_fm_b_b#/config") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/\\#5#resolver_fm_b_b#resolver_fm_b_b#/config/something") + "system:/elektra/mountpoints/user:\\/somewhere/errorplugins/#5#resolver_fm_b_b#resolver_fm_b_b#/config/something") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "a val") << "string of element in keyset wrong"; mountConfig.next (); @@ -567,20 +564,20 @@ TEST (Backend, SimpleBackendWithUnderscore) << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/\\#0#resolver_fm_b_b") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/#0#resolver_fm_b_b") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/\\#5#dump#dump#") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/#5#dump#dump#") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/\\#5#dump#dump#/config") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/getplugins/#5#dump#dump#/config") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); EXPECT_EQ (mountConfig.current ().getName (), - "system:/elektra/mountpoints/user:\\/somewhere/getplugins/\\#5#dump#dump#/config/res/conf") + "system:/elektra/mountpoints/user:\\/somewhere/getplugins/#5#dump#dump#/config/res/conf") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "do it") << "string of element in keyset wrong"; mountConfig.next (); @@ -592,15 +589,15 @@ TEST (Backend, SimpleBackendWithUnderscore) << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/\\#0#resolver_fm_b_b") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/#0#resolver_fm_b_b") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/\\#5#dump") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/#5#dump") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; mountConfig.next (); - EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/\\#7#resolver_fm_b_b") + EXPECT_EQ (mountConfig.current ().getName (), "system:/elektra/mountpoints/user:\\/somewhere/setplugins/#7#resolver_fm_b_b") << "name of element in keyset wrong"; EXPECT_EQ (mountConfig.current ().getString (), "") << "string of element in keyset wrong"; } diff --git a/src/plugins/augeas/augeas.c b/src/plugins/augeas/augeas.c index c909ef3332f..f4b38b90e28 100644 --- a/src/plugins/augeas/augeas.c +++ b/src/plugins/augeas/augeas.c @@ -411,7 +411,7 @@ static int saveTree (augeas * augeasHandle, KeySet * ks, const char * lensPath, if (strcmp (keyBaseName (key), "#comment") == 0) { - size_t offset = strlen (nodeName) - sizeof ("\\#comment") + 1; + size_t offset = strlen (nodeName) - sizeof ("#comment") + 1; strcpy (nodeName + offset, "#comment"); } diff --git a/src/plugins/augeas/testmod_augeas.c b/src/plugins/augeas/testmod_augeas.c index 7fa5d1d789c..a85b6aab26d 100644 --- a/src/plugins/augeas/testmod_augeas.c +++ b/src/plugins/augeas/testmod_augeas.c @@ -88,9 +88,9 @@ static void test_hostLensWrite (char * fileName) KEY_META, "order", "10", KEY_END), keyNew ("user:/tests/augeas-hosts/1/canonical", KEY_VALUE, "localhost", KEY_META, "order", "20", KEY_END), - keyNew ("user:/tests/augeas-hosts/1/\\#comment", KEY_VALUE, + keyNew ("user:/tests/augeas-hosts/1/#comment", KEY_VALUE, "hostcomment", KEY_META, "order", "21", KEY_END), - keyNew ("user:/tests/augeas-hosts/\\#comment", KEY_VALUE, + keyNew ("user:/tests/augeas-hosts/#comment", KEY_VALUE, "linecomment", KEY_META, "order", "22", KEY_END), keyNew ("user:/tests/augeas-hosts/2/ipaddr", KEY_VALUE, "192.168.0.1", KEY_META, "order", "30", KEY_END), @@ -152,7 +152,7 @@ static void test_hostLensDelete (char * sourceFile, char * compFile) elektraKsPopAtCursor (ks, ksGetCursor (ks)); keyDel (key); - key = ksLookupByName (ks, "user:/tests/augeas-hosts/1/\\#comment", 0); + key = ksLookupByName (ks, "user:/tests/augeas-hosts/1/#comment", 0); return_if_fail (key, "comment of localhost not found"); elektraKsPopAtCursor (ks, ksGetCursor (ks)); keyDel (key); @@ -193,7 +193,7 @@ static void test_hostLensModify (char * sourceFile, char * compFile) return_if_fail (key, "ip address of host2 not found"); keySetString (key, "fd00::4711:4712:2::2"); - key = ksLookupByName (ks, "user:/tests/augeas-hosts/\\#comment", 0); + key = ksLookupByName (ks, "user:/tests/augeas-hosts/#comment", 0); return_if_fail (key, "line comment not found"); keySetString (key, "line comment modified"); diff --git a/src/plugins/yajl/yajl_gen.c b/src/plugins/yajl/yajl_gen.c index 4e891d0d741..1a714209d8b 100644 --- a/src/plugins/yajl/yajl_gen.c +++ b/src/plugins/yajl/yajl_gen.c @@ -27,13 +27,13 @@ lookahead_t elektraLookahead (const char * pnext, size_t size) if (*(pnext + size) == '/') { // we are not at end, so we can look one further - if (*(pnext + size + 1) == '#') + if (strcmp (pnext + size + 1, "###empty_array") == 0) { - lookahead = LOOKAHEAD_ARRAY; + lookahead = LOOKAHEAD_EMPTY_ARRAY; } - else if (strcmp (pnext + size + 1, "\\###empty_array") == 0) + else if (*(pnext + size + 1) == '#') { - lookahead = LOOKAHEAD_EMPTY_ARRAY; + lookahead = LOOKAHEAD_ARRAY; } else { @@ -89,7 +89,7 @@ static int elektraGenOpenValue (yajl_gen g, const Key * next) ELEKTRA_LOG_DEBUG ("next: \"%.*s\"", (int) last.size, last.current); - if (strcmp (last.current, "\\###empty_array") == 0) + if (strcmp (last.current, "###empty_array") == 0) { ELEKTRA_LOG_DEBUG ("GEN empty array in value"); yajl_gen_array_open (g); diff --git a/src/plugins/yamlcpp/README.md b/src/plugins/yamlcpp/README.md index 0662e3d35dc..6a2de4cbf9f 100644 --- a/src/plugins/yamlcpp/README.md +++ b/src/plugins/yamlcpp/README.md @@ -105,7 +105,7 @@ kdb set user:/tests/yamlcpp/sunny/#4 Mac kdb set user:/tests/yamlcpp/sunny/#_10 'The Waitress' kdb meta-get user:/tests/yamlcpp/sunny array #> #_10 -kdb get user:/tests/yamlcpp/sunny/\\#_9 +kdb get user:/tests/yamlcpp/sunny/#_9 # RET: 11 # Retrieve the last array entry diff --git a/tests/abi/testabi_key.c b/tests/abi/testabi_key.c index d6393e26dbb..5716fddc04b 100644 --- a/tests/abi/testabi_key.c +++ b/tests/abi/testabi_key.c @@ -1738,20 +1738,20 @@ static void test_keyNameSpecial (void) succeed_if_same_string (keyName (k), "system:/"); - succeed_if (keySetName (k, "system:/../something"), "could set key name with too many .."); - succeed_if_same_string (keyName (k), "system:/"); + succeed_if (keySetName (k, "system:/../something"), "could not set key name with too many .."); + succeed_if_same_string (keyName (k), "system:/something"); succeed_if (keySetName (k, "system:/../../something"), "could not set key name with too many .."); - succeed_if_same_string (keyName (k), "system:/"); + succeed_if_same_string (keyName (k), "system:/something"); succeed_if (keySetName (k, "system:/../../../something"), "could not set key name with too many .."); - succeed_if_same_string (keyName (k), "system:/"); + succeed_if_same_string (keyName (k), "system:/something"); succeed_if (keySetName (k, "system:/../../../../something"), "could not set key name with too many .."); - succeed_if_same_string (keyName (k), "system:/"); + succeed_if_same_string (keyName (k), "system:/something"); succeed_if (keySetName (k, "system:/../../../../../something"), "could not set key name with too many .."); - succeed_if_same_string (keyName (k), "system:/"); + succeed_if_same_string (keyName (k), "system:/something"); succeed_if (keySetName (k, "system:/a/b/c/.."), "could not set key name with .."); @@ -1771,19 +1771,19 @@ static void test_keyNameSpecial (void) succeed_if (keySetName (k, "system:/../a/b/c"), "could not set key name with too many .."); - succeed_if_same_string (keyName (k), "system:/"); + succeed_if_same_string (keyName (k), "system:/a/b/c"); succeed_if (keySetName (k, "system:/../../a/b/c"), "could not set key name with too many .."); - succeed_if_same_string (keyName (k), "system:/"); + succeed_if_same_string (keyName (k), "system:/a/b/c"); succeed_if (keySetName (k, "system:/../../../a/b/c"), "could not set key name with too many .."); - succeed_if_same_string (keyName (k), "system:/"); + succeed_if_same_string (keyName (k), "system:/a/b/c"); succeed_if (keySetName (k, "system:/../../../../a/b/c"), "could not set key name with too many .."); - succeed_if_same_string (keyName (k), "system:/"); + succeed_if_same_string (keyName (k), "system:/a/b/c"); succeed_if (keySetName (k, "system:/../../../../../a/b/c"), "could not set key name with too many .."); - succeed_if_same_string (keyName (k), "system:/"); + succeed_if_same_string (keyName (k), "system:/a/b/c"); keyDel (k); @@ -2462,17 +2462,17 @@ void test_keyCascading (void) keySetName (k, "/"); succeed_if (keyGetNameSize (k) == 2, "size not correct"); - succeed_if (keyAddName (k, "/////..") < 0, "try to substract root with .."); + succeed_if (keyAddName (k, "/////..") == 2, "could not add nothing with .."); succeed_if (keyGetNameSize (k) == 2, "size not correct"); succeed_if_same_string (keyName (k), "/"); succeed_if_same_string (keyBaseName (k), ""); keySetName (k, "/"); succeed_if (keyGetNameSize (k) == 2, "size not correct"); - succeed_if (keyAddName (k, "/////../more") < 0, "try to substract root with .."); - succeed_if (keyGetNameSize (k) == sizeof ("/"), "size not correct"); - succeed_if_same_string (keyName (k), "/"); - succeed_if_same_string (keyBaseName (k), ""); + succeed_if (keyAddName (k, "/////../more") == 6, "could not add more with .."); + succeed_if (keyGetNameSize (k) == 6, "size not correct"); + succeed_if_same_string (keyName (k), "/more"); + succeed_if_same_string (keyBaseName (k), "more"); keySetName (k, "/"); diff --git a/tests/abi/testabi_ks.c b/tests/abi/testabi_ks.c index 8330f91bbdd..4dea7f207be 100644 --- a/tests/abi/testabi_ks.c +++ b/tests/abi/testabi_ks.c @@ -2051,7 +2051,7 @@ static void test_ksOrder (void) ks = ksNew (20, keyNew ("user:/x", KEY_END), keyNew ("user:/x/%", KEY_END), keyNew ("user:/x/%/a", KEY_END), keyNew ("user:/x/%/b", KEY_END), keyNew ("user:/x/\\%", KEY_END), keyNew ("user:/x/\\%/a", KEY_END), keyNew ("user:/x/\\%/b", KEY_END), keyNew ("user:/x/A", KEY_END), keyNew ("user:/x/A/a", KEY_END), - keyNew ("user:/x/A/b", KEY_END), keyNew ("user:/x/\\%a", KEY_END), keyNew ("user:/x/\\%b", KEY_END), + keyNew ("user:/x/A/b", KEY_END), keyNew ("user:/x/%a", KEY_END), keyNew ("user:/x/%b", KEY_END), keyNew ("user:/x/a\\/", KEY_END), keyNew ("user:/x/a\\/b", KEY_END), keyNew ("user:/x/a\\/b/a", KEY_END), keyNew ("user:/x/a\\/b/b", KEY_END), keyNew ("user:/x/aA", KEY_END), keyNew ("user:/x/aA/a", KEY_END), keyNew ("user:/x/aA/b", KEY_END), keyNew ("user:/x/aa", KEY_END), keyNew ("user:/x/aa/a", KEY_END), @@ -2073,9 +2073,9 @@ static void test_ksOrder (void) ksNext (ks); succeed_if_same_string (keyName (ksCurrent (ks)), "user:/x/\\%/b"); ksNext (ks); - succeed_if_same_string (keyName (ksCurrent (ks)), "user:/x/\\%a"); + succeed_if_same_string (keyName (ksCurrent (ks)), "user:/x/%a"); ksNext (ks); - succeed_if_same_string (keyName (ksCurrent (ks)), "user:/x/\\%b"); + succeed_if_same_string (keyName (ksCurrent (ks)), "user:/x/%b"); ksNext (ks); succeed_if_same_string (keyName (ksCurrent (ks)), "user:/x/A"); ksNext (ks); @@ -2523,18 +2523,18 @@ KeySet * set_simple (void) keyNew ("system:/elektra/mountpoints/simple/config/path", KEY_END), keyNew ("system:/elektra/mountpoints/simple/getplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1tracer", KEY_VALUE, "tracer", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1tracer/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1tracer/config/anything", KEY_VALUE, "plugin", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1tracer/config/more", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1tracer/config/more/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1tracer/config/more/config/below", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1tracer/config/path", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1tracer", KEY_VALUE, "tracer", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1tracer/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1tracer/config/anything", KEY_VALUE, "plugin", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1tracer/config/more", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1tracer/config/more/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1tracer/config/more/config/below", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1tracer/config/path", KEY_END), keyNew ("system:/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user:/tests/backend/simple", KEY_END), keyNew ("system:/elektra/mountpoints/simple/setplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/setplugins/\\#1tracer", KEY_VALUE, "tracer", KEY_END), KS_END); + keyNew ("system:/elektra/mountpoints/simple/setplugins/#1tracer", KEY_VALUE, "tracer", KEY_END), KS_END); } static void test_simple (void) @@ -2549,16 +2549,16 @@ static void test_simple (void) KeySet * result_config = ksNew (22, keyNew ("system:/elektra/mountpoints/simple", KEY_END), keyNew ("system:/elektra/mountpoints/simple/getplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1tracer", KEY_VALUE, "tracer", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1tracer/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1tracer/config/anything", KEY_VALUE, "plugin", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1tracer/config/more", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1tracer/config/more/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1tracer/config/more/config/below", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1tracer/config/path", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1tracer", KEY_VALUE, "tracer", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1tracer/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1tracer/config/anything", KEY_VALUE, "plugin", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1tracer/config/more", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1tracer/config/more/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1tracer/config/more/config/below", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1tracer/config/path", KEY_END), keyNew ("system:/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user:/tests/backend/simple", KEY_END), keyNew ("system:/elektra/mountpoints/simple/setplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/setplugins/\\#1tracer", KEY_VALUE, "tracer", KEY_END), KS_END); + keyNew ("system:/elektra/mountpoints/simple/setplugins/#1tracer", KEY_VALUE, "tracer", KEY_END), KS_END); Key * key = ksLookup (config, keyNew ("system:/elektra/mountpoints/simple/config", KEY_END), KDB_O_DEL); succeed_if (ksGetCursor (config) == 1, "cursor not set correctly"); KeySet * res = ksCut (config, key); diff --git a/tests/ctest/test_backend.c b/tests/ctest/test_backend.c index e3c047321b7..1ea780a2152 100644 --- a/tests/ctest/test_backend.c +++ b/tests/ctest/test_backend.c @@ -12,36 +12,35 @@ KeySet * set_simple (void) { - return ksNew ( - 50, keyNew ("system:/elektra/mountpoints/simple", KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/anything", KEY_VALUE, "backend", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/more", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/more/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/more/config/below", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/path", KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/errorplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/errorplugins/\\#1" KDB_DEFAULT_STORAGE, KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/getplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE, KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/anything", KEY_VALUE, "plugin", - KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/more", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/more/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/more/config/below", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/path", KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user:/tests/backend/simple", KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/setplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/setplugins/\\#1" KDB_DEFAULT_STORAGE, KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/errorplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/errorplugins/\\#1" KDB_DEFAULT_STORAGE, KEY_END), KS_END); + return ksNew (50, keyNew ("system:/elektra/mountpoints/simple", KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/anything", KEY_VALUE, "backend", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/more", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/more/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/more/config/below", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/path", KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/errorplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/errorplugins/#1" KDB_DEFAULT_STORAGE, KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/getplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE, KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/anything", KEY_VALUE, + "plugin", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more/config/below", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/path", KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user:/tests/backend/simple", KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/setplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/setplugins/#1" KDB_DEFAULT_STORAGE, KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/errorplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/errorplugins/#1" KDB_DEFAULT_STORAGE, KEY_END), KS_END); } KeySet * set_pluginconf (void) @@ -155,46 +154,44 @@ static void test_default (void) KeySet * set_backref (void) { - return ksNew (50, keyNew ("system:/elektra/mountpoints/backref", KEY_END), - - keyNew ("system:/elektra/mountpoints/backref/config", KEY_END), - keyNew ("system:/elektra/mountpoints/backref/config/anything", KEY_VALUE, "backend", KEY_END), - keyNew ("system:/elektra/mountpoints/backref/config/more", KEY_END), - keyNew ("system:/elektra/mountpoints/backref/config/more/config", KEY_END), - keyNew ("system:/elektra/mountpoints/backref/config/more/config/below", KEY_END), - keyNew ("system:/elektra/mountpoints/backref/config/path", KEY_END), - - keyNew ("system:/elektra/mountpoints/backref/errorplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/backref/errorplugins/\\#1#" KDB_DEFAULT_STORAGE "#" KDB_DEFAULT_STORAGE "#", - KEY_VALUE, "introduce reference", KEY_END), - keyNew ("system:/elektra/mountpoints/backref/errorplugins/\\#1#" KDB_DEFAULT_STORAGE "#" KDB_DEFAULT_STORAGE - "#/config", - KEY_END), - keyNew ("system:/elektra/mountpoints/backref/errorplugins/\\#1#" KDB_DEFAULT_STORAGE "#" KDB_DEFAULT_STORAGE - "#/config/anything", - KEY_VALUE, "plugin", KEY_END), - keyNew ("system:/elektra/mountpoints/backref/errorplugins/\\#1#" KDB_DEFAULT_STORAGE "#" KDB_DEFAULT_STORAGE - "#/config/more", - KEY_END), - keyNew ("system:/elektra/mountpoints/backref/errorplugins/\\#1#" KDB_DEFAULT_STORAGE "#" KDB_DEFAULT_STORAGE - "#/config/more/config", - KEY_END), - keyNew ("system:/elektra/mountpoints/backref/errorplugins/\\#1#" KDB_DEFAULT_STORAGE "#" KDB_DEFAULT_STORAGE - "#/config/more/config/below", - KEY_END), - keyNew ("system:/elektra/mountpoints/backref/errorplugins/\\#1#" KDB_DEFAULT_STORAGE "#" KDB_DEFAULT_STORAGE - "#/config/path", - KEY_END), - - keyNew ("system:/elektra/mountpoints/backref/getplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/backref/getplugins/\\#1#" KDB_DEFAULT_STORAGE, KEY_VALUE, "backend", KEY_END), - - keyNew ("system:/elektra/mountpoints/backref/mountpoint", KEY_VALUE, "user:/tests/backend/backref", KEY_END), - - keyNew ("system:/elektra/mountpoints/backref/setplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/backref/setplugins/\\#1#" KDB_DEFAULT_STORAGE, KEY_VALUE, - "reference to other default", KEY_END), - KS_END); + return ksNew ( + 50, keyNew ("system:/elektra/mountpoints/backref", KEY_END), + + keyNew ("system:/elektra/mountpoints/backref/config", KEY_END), + keyNew ("system:/elektra/mountpoints/backref/config/anything", KEY_VALUE, "backend", KEY_END), + keyNew ("system:/elektra/mountpoints/backref/config/more", KEY_END), + keyNew ("system:/elektra/mountpoints/backref/config/more/config", KEY_END), + keyNew ("system:/elektra/mountpoints/backref/config/more/config/below", KEY_END), + keyNew ("system:/elektra/mountpoints/backref/config/path", KEY_END), + + keyNew ("system:/elektra/mountpoints/backref/errorplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/backref/errorplugins/#1#" KDB_DEFAULT_STORAGE "#" KDB_DEFAULT_STORAGE "#", KEY_VALUE, + "introduce reference", KEY_END), + keyNew ("system:/elektra/mountpoints/backref/errorplugins/#1#" KDB_DEFAULT_STORAGE "#" KDB_DEFAULT_STORAGE "#/config", + KEY_END), + keyNew ("system:/elektra/mountpoints/backref/errorplugins/#1#" KDB_DEFAULT_STORAGE "#" KDB_DEFAULT_STORAGE + "#/config/anything", + KEY_VALUE, "plugin", KEY_END), + keyNew ("system:/elektra/mountpoints/backref/errorplugins/#1#" KDB_DEFAULT_STORAGE "#" KDB_DEFAULT_STORAGE "#/config/more", + KEY_END), + keyNew ("system:/elektra/mountpoints/backref/errorplugins/#1#" KDB_DEFAULT_STORAGE "#" KDB_DEFAULT_STORAGE + "#/config/more/config", + KEY_END), + keyNew ("system:/elektra/mountpoints/backref/errorplugins/#1#" KDB_DEFAULT_STORAGE "#" KDB_DEFAULT_STORAGE + "#/config/more/config/below", + KEY_END), + keyNew ("system:/elektra/mountpoints/backref/errorplugins/#1#" KDB_DEFAULT_STORAGE "#" KDB_DEFAULT_STORAGE "#/config/path", + KEY_END), + + keyNew ("system:/elektra/mountpoints/backref/getplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/backref/getplugins/#1#" KDB_DEFAULT_STORAGE, KEY_VALUE, "backend", KEY_END), + + keyNew ("system:/elektra/mountpoints/backref/mountpoint", KEY_VALUE, "user:/tests/backend/backref", KEY_END), + + keyNew ("system:/elektra/mountpoints/backref/setplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/backref/setplugins/#1#" KDB_DEFAULT_STORAGE, KEY_VALUE, "reference to other default", + KEY_END), + KS_END); } static void test_backref (void) diff --git a/tests/ctest/test_globbing.c b/tests/ctest/test_globbing.c index 3f4d657f09f..7dccd2e52fd 100644 --- a/tests/ctest/test_globbing.c +++ b/tests/ctest/test_globbing.c @@ -70,7 +70,7 @@ static void test_underscore (void) should_match (BASE_KEY "/longkey123__31", BASE_KEY "/_"); should_match (BASE_KEY "/1231412", BASE_KEY "/_"); should_match (BASE_KEY "/\\#1231231", BASE_KEY "/_"); - should_match (BASE_KEY "/\\#__1234", BASE_KEY "/_"); + should_match (BASE_KEY "/#__1234", BASE_KEY "/_"); should_match (BASE_KEY "/????aased12355", BASE_KEY "/_"); should_match (BASE_KEY "/***", BASE_KEY "/_"); should_match (BASE_KEY "/_", BASE_KEY "/_"); @@ -101,7 +101,7 @@ static void test_hash (void) should_not_match (BASE_KEY "/longkey123__31", BASE_KEY "/#"); should_not_match (BASE_KEY "/1231412", BASE_KEY "/#"); should_not_match (BASE_KEY "/\\#1231231", BASE_KEY "/#"); - should_not_match (BASE_KEY "/\\#__1234", BASE_KEY "/#"); + should_not_match (BASE_KEY "/#__1234", BASE_KEY "/#"); should_not_match (BASE_KEY "/????aased12355", BASE_KEY "/#"); should_not_match (BASE_KEY "/***", BASE_KEY "/#"); should_not_match (BASE_KEY "/#", BASE_KEY "/#"); diff --git a/tests/ctest/test_internal.c b/tests/ctest/test_internal.c index 0c890462752..bc8084a548c 100644 --- a/tests/ctest/test_internal.c +++ b/tests/ctest/test_internal.c @@ -64,15 +64,13 @@ static void test_elektraStrLen (void) #define TEST_VALIDATE_NAME_OK(NAME, MSG) \ do \ { \ - size_t s = 2, u = 3; \ - succeed_if (elektraKeyNameValidate (NAME, "/", &s, &u), MSG " ok"); \ + succeed_if (elektraKeyNameValidate (NAME, false), MSG " ok"); \ } while (0) #define TEST_VALIDATE_NAME_NOK(NAME, MSG) \ do \ { \ - size_t s = 2, u = 3; \ - succeed_if (!elektraKeyNameValidate (NAME, "/", &s, &u), MSG "not ok"); \ + succeed_if (!elektraKeyNameValidate (NAME, false), MSG "not ok"); \ } while (0) static void test_elektraKeyNameValidate (void) @@ -141,23 +139,23 @@ static void test_elektraKeyNameUnescape (void) char * dest = buf; char * p = NULL; - elektraKeyNameUnescape ("/abc", &dest); + elektraKeyNameUnescape ("/abc", dest); succeed_if_same_string ("abc", dest + 2); - elektraKeyNameUnescape ("/\\\\.", &dest); + elektraKeyNameUnescape ("/\\\\.", dest); succeed_if_same_string ("\\.", dest + 2); - elektraKeyNameUnescape ("/abc/def", &dest); + elektraKeyNameUnescape ("/abc/def", dest); p = dest + 2; succeed_if_same_string ("abc", p); p += 4; succeed_if_same_string ("def", p); - elektraKeyNameUnescape ("/abc\\/def", &dest); + elektraKeyNameUnescape ("/abc\\/def", dest); p = dest + 2; succeed_if_same_string ("abc/def", p); - elektraKeyNameUnescape ("/abc/%/def", &dest); + elektraKeyNameUnescape ("/abc/%/def", dest); p = dest + 2; succeed_if_same_string ("abc", p); p += 4; @@ -165,7 +163,7 @@ static void test_elektraKeyNameUnescape (void) p += 1; succeed_if_same_string ("def", p); - elektraKeyNameUnescape ("/abc/\\%/def", &dest); + elektraKeyNameUnescape ("/abc/\\%/def", dest); p = dest + 2; succeed_if_same_string ("abc", p); p += 4; @@ -173,7 +171,7 @@ static void test_elektraKeyNameUnescape (void) p += 2; succeed_if_same_string ("def", p); - elektraKeyNameUnescape ("/abc/\\./def", &dest); + elektraKeyNameUnescape ("/abc/\\./def", dest); p = dest + 2; succeed_if_same_string ("abc", p); p += 4; @@ -181,7 +179,7 @@ static void test_elektraKeyNameUnescape (void) p += 2; succeed_if_same_string ("def", p); - elektraKeyNameUnescape ("/abc/\\../def", &dest); + elektraKeyNameUnescape ("/abc/\\../def", dest); p = dest + 2; succeed_if_same_string ("abc", p); p += 4; @@ -189,7 +187,7 @@ static void test_elektraKeyNameUnescape (void) p += 3; succeed_if_same_string ("def", p); - elektraKeyNameUnescape ("/abc/\\\\../def", &dest); + elektraKeyNameUnescape ("/abc/\\\\../def", dest); p = dest + 2; succeed_if_same_string ("abc", p); p += 4; @@ -197,7 +195,7 @@ static void test_elektraKeyNameUnescape (void) p += 4; succeed_if_same_string ("def", p); - elektraKeyNameUnescape ("/a\\\\c/\\../d\\\\f", &dest); + elektraKeyNameUnescape ("/a\\\\c/\\../d\\\\f", dest); p = dest + 2; succeed_if_same_string ("a\\c", p); p += 4; @@ -205,7 +203,7 @@ static void test_elektraKeyNameUnescape (void) p += 3; succeed_if_same_string ("d\\f", p); - elektraKeyNameUnescape ("/\\\\bc/\\%/\\\\ef", &dest); + elektraKeyNameUnescape ("/\\\\bc/\\%/\\\\ef", dest); p = dest + 2; succeed_if_same_string ("\\bc", p); p += 4; @@ -213,7 +211,7 @@ static void test_elektraKeyNameUnescape (void) p += 2; succeed_if_same_string ("\\ef", p); - elektraKeyNameUnescape ("/\\\\b/\\%/\\\\e", &dest); + elektraKeyNameUnescape ("/\\\\b/\\%/\\\\e", dest); p = dest + 2; succeed_if_same_string ("\\b", p); p += 3; @@ -221,7 +219,7 @@ static void test_elektraKeyNameUnescape (void) p += 2; succeed_if_same_string ("\\e", p); - elektraKeyNameUnescape ("/\\\\b/\\\\%/\\\\e", &dest); + elektraKeyNameUnescape ("/\\\\b/\\\\%/\\\\e", dest); p = dest + 2; succeed_if_same_string ("\\b", p); p += 3; @@ -229,31 +227,31 @@ static void test_elektraKeyNameUnescape (void) p += 3; succeed_if_same_string ("\\e", p); - elektraKeyNameUnescape ("/a\\/\\/def", &dest); + elektraKeyNameUnescape ("/a\\/\\/def", dest); p = dest + 2; succeed_if_same_string ("a//def", p); - elektraKeyNameUnescape ("/\\/\\/\\/def", &dest); + elektraKeyNameUnescape ("/\\/\\/\\/def", dest); p = dest + 2; succeed_if_same_string ("///def", p); - elektraKeyNameUnescape ("/\\/\\/\\/def", &dest); + elektraKeyNameUnescape ("/\\/\\/\\/def", dest); p = dest + 2; succeed_if_same_string ("///def", p); - elektraKeyNameUnescape ("/\\/\\/\\/\\/\\/\\/", &dest); + elektraKeyNameUnescape ("/\\/\\/\\/\\/\\/\\/", dest); p = dest + 2; succeed_if_same_string ("//////", p); - elektraKeyNameUnescape ("/\\/\\/%\\/\\/\\/", &dest); + elektraKeyNameUnescape ("/\\/\\/%\\/\\/\\/", dest); p = dest + 2; succeed_if_same_string ("//%///", p); - elektraKeyNameUnescape ("/\\/\\/..\\/\\/", &dest); + elektraKeyNameUnescape ("/\\/\\/..\\/\\/", dest); p = dest + 2; succeed_if_same_string ("//..//", p); - elektraKeyNameUnescape ("/bar\\/foo_bar\\/", &dest); + elektraKeyNameUnescape ("/bar\\/foo_bar\\/", dest); p = dest + 2; succeed_if_same_string ("bar/foo_bar/", p); } diff --git a/tests/ctest/test_key.c b/tests/ctest/test_key.c index e8f40a75f4b..18fdf49822d 100644 --- a/tests/ctest/test_key.c +++ b/tests/ctest/test_key.c @@ -165,7 +165,7 @@ static void test_keyNameUnescape (void) char a[] = "/\\\\a"; char s[] = "\0\0\\a"; s[0] = KEY_NS_CASCADING; - elektraKeyNameUnescape (a, &buffer); + elektraKeyNameUnescape (a, buffer); succeed_if (!memcmp (buffer, s, sizeof (s)), "unescaped name wrong"); } @@ -173,7 +173,7 @@ static void test_keyNameUnescape (void) char a[] = "/a\\/test"; char s[] = "\0\0a/test"; s[0] = KEY_NS_CASCADING; - elektraKeyNameUnescape (a, &buffer); + elektraKeyNameUnescape (a, buffer); succeed_if (!memcmp (buffer, s, sizeof (s)), "unescaped name wrong"); } @@ -181,7 +181,7 @@ static void test_keyNameUnescape (void) char a[] = "/a\\\\\\/test"; char s[] = "\0\0a\\/test"; s[0] = KEY_NS_CASCADING; - elektraKeyNameUnescape (a, &buffer); + elektraKeyNameUnescape (a, buffer); succeed_if (!memcmp (buffer, s, sizeof (s)), "unescaped name wrong"); } @@ -189,7 +189,7 @@ static void test_keyNameUnescape (void) char a[] = "/a\\\\\\\\\\/test"; char s[] = "\0\0a\\\\/test"; s[0] = KEY_NS_CASCADING; - elektraKeyNameUnescape (a, &buffer); + elektraKeyNameUnescape (a, buffer); succeed_if (!memcmp (buffer, s, sizeof (s)), "unescaped name wrong"); } @@ -199,7 +199,7 @@ static void test_keyNameUnescape (void) char a[] = "user:/a/test"; char s[] = "\0\0a\0test"; s[0] = KEY_NS_USER; - elektraKeyNameUnescape (a, &buffer); + elektraKeyNameUnescape (a, buffer); succeed_if (!memcmp (buffer, s, sizeof (s)), "unescaped name wrong"); } @@ -207,7 +207,7 @@ static void test_keyNameUnescape (void) char a[] = "user:/a\\/test"; char s[] = "\0\0a/test"; s[0] = KEY_NS_USER; - elektraKeyNameUnescape (a, &buffer); + elektraKeyNameUnescape (a, buffer); succeed_if (!memcmp (buffer, s, sizeof (s)), "unescaped name wrong"); } @@ -215,7 +215,7 @@ static void test_keyNameUnescape (void) char a[] = "user:/a\\\\/test"; char s[] = "\0\0a\\\0test"; s[0] = KEY_NS_USER; - elektraKeyNameUnescape (a, &buffer); + elektraKeyNameUnescape (a, buffer); succeed_if (!memcmp (buffer, s, sizeof (s)), "unescaped name wrong"); } @@ -223,7 +223,7 @@ static void test_keyNameUnescape (void) char a[] = "user:/\\\\/test"; char s[] = "\0\0\\\0test"; s[0] = KEY_NS_USER; - elektraKeyNameUnescape (a, &buffer); + elektraKeyNameUnescape (a, buffer); succeed_if (!memcmp (buffer, s, sizeof (s)), "unescaped name wrong"); } } @@ -627,7 +627,7 @@ static void test_keyAddName (void) TEST_ADD_NAME ("user:/", "./user", "user:/user"); TEST_ADD_NAME ("user:/", "/./user", "user:/user"); TEST_ADD_NAME ("user:/", "/////./user", "user:/user"); - TEST_ADD_NAME_ERROR ("user:/", "../user"); + TEST_ADD_NAME ("user:/", "../user", "user:/user"); TEST_ADD_NAME ("user:/verylongstringtoremove", "../x", "user:/x"); TEST_ADD_NAME ("user:/huhu", "../x", "user:/x"); @@ -645,11 +645,6 @@ static void test_keyAddName (void) TEST_ADD_NAME ("/more/level", "../..//user", "/user"); TEST_ADD_NAME ("/much/more/level/1/2/3", "../../../../../..//user", "/user"); - TEST_ADD_NAME_ERROR ("/much/more/level/1/2/3", "../../../../../../..//user"); - TEST_ADD_NAME_ERROR ("/much/more/level/1/2/3", "..///../../../../../../..//user"); - TEST_ADD_NAME_ERROR ("/much/more/level/1/2/3", "..///../../..////../../../..//user"); - TEST_ADD_NAME_ERROR ("/much/more/level/1/2/3", "../../....///../../..////../../../..//user"); - TEST_ADD_NAME ("/s", ".../user", "/s/.../user"); TEST_ADD_NAME ("/s", "..a/user", "/s/..a/user"); TEST_ADD_NAME ("/s", "..../user", "/s/..../user"); diff --git a/tests/ctest/test_keyname.c b/tests/ctest/test_keyname.c index 47806a51e04..2a1db4c487b 100644 --- a/tests/ctest/test_keyname.c +++ b/tests/ctest/test_keyname.c @@ -10,622 +10,675 @@ #include "tests.h" -#define TEST_VALIDATE_OK(name, prefix, usizeOld, csizeNew, usizeNew) \ +#define TEST_VALIDATE_OK(name, prefix) \ do \ { \ - size_t csize = prefix == NULL ? 0 : sizeof (prefix); \ - size_t usize = usizeOld; \ - succeed_if_fmt (elektraKeyNameValidate (name, prefix, &csize, &usize), "'%s' + '%s' SHOULD BE a valid key name", \ + succeed_if_fmt (elektraKeyNameValidate (name, prefix == NULL), "'%s' + '%s' SHOULD BE a valid key name", \ prefix == NULL ? "" : prefix, name); \ - succeed_if_fmt (csize == csizeNew, "'%s' + '%s': canonical size wrong (act != exp): %zu != %zu", \ - prefix == NULL ? "" : prefix, name, csize, (size_t) csizeNew); \ - succeed_if_fmt (usize == usizeNew, "'%s' + '%s': unescaped size wrong (act != exp): %zu != %zu", \ - prefix == NULL ? "" : prefix, name, usize, (size_t) usizeNew); \ } while (0) -#define TEST_VALIDATE_ERROR(name, prefix, usizeOld) \ +#define TEST_VALIDATE_ERROR(name, prefix) \ do \ { \ - size_t c = prefix == NULL ? 1234 : sizeof (prefix); \ - size_t u = usizeOld; \ - succeed_if_fmt (!elektraKeyNameValidate (name, prefix, &c, &u), "'%s' + '%s' SHOULD NOT BE a valid key name", \ + succeed_if_fmt (!elektraKeyNameValidate (name, prefix == NULL), "'%s' + '%s' SHOULD NOT BE a valid key name", \ prefix == NULL ? "" : prefix, name); \ - succeed_if_fmt (c == (prefix == NULL ? 1234 : sizeof (prefix)), "'%s' + '%s': ERROR case MUST NOT change canonical size", \ - prefix == NULL ? "" : prefix, name); \ - succeed_if_fmt (u == usizeOld, "'%s' + '%s': ERROR case MUST NOT change unescaped size", prefix == NULL ? "" : prefix, \ - name); \ } while (0) static void test_validate (void) { - TEST_VALIDATE_OK ("/", NULL, 0, 2, 3); - TEST_VALIDATE_OK ("proc:/", NULL, 0, 7, 3); - TEST_VALIDATE_OK ("dir:/", NULL, 0, 6, 3); - TEST_VALIDATE_OK ("user:/", NULL, 0, 7, 3); - TEST_VALIDATE_OK ("system:/", NULL, 0, 9, 3); - TEST_VALIDATE_OK ("spec:/", NULL, 0, 7, 3); - TEST_VALIDATE_OK ("meta:/", NULL, 0, 7, 3); - TEST_VALIDATE_OK ("default:/", NULL, 0, 10, 3); - - TEST_VALIDATE_OK ("/a", NULL, 0, 3, 4); - TEST_VALIDATE_OK ("/ab", NULL, 0, 4, 5); - TEST_VALIDATE_OK ("/abc", NULL, 0, 5, 6); - - TEST_VALIDATE_OK ("/a", NULL, 123, 3, 4); - TEST_VALIDATE_OK ("/ab", NULL, 22, 4, 5); - TEST_VALIDATE_OK ("/abc", NULL, 33, 5, 6); - - TEST_VALIDATE_OK ("/%", NULL, 0, 3, 3); - TEST_VALIDATE_OK ("/\\%", NULL, 0, 4, 4); - TEST_VALIDATE_OK ("/\\\\%", NULL, 0, 5, 5); - TEST_VALIDATE_OK ("/\\\\\\\\%", NULL, 0, 7, 6); - - TEST_VALIDATE_OK ("/\\/", NULL, 0, 4, 4); - TEST_VALIDATE_OK ("/\\\\/", NULL, 0, 4, 4); - TEST_VALIDATE_OK ("/\\\\\\/", NULL, 0, 6, 5); - TEST_VALIDATE_OK ("/\\\\\\\\/", NULL, 0, 6, 5); - TEST_VALIDATE_OK ("/\\\\\\\\\\/", NULL, 0, 8, 6); - - TEST_VALIDATE_OK ("/\\/", NULL, 0, 4, 4); - TEST_VALIDATE_OK ("/\\\\", NULL, 0, 4, 4); - TEST_VALIDATE_OK ("/\\\\\\/", NULL, 0, 6, 5); - TEST_VALIDATE_OK ("/\\\\\\\\", NULL, 0, 6, 5); - TEST_VALIDATE_OK ("/\\\\\\\\\\/", NULL, 0, 8, 6); - - TEST_VALIDATE_OK ("/\\//", NULL, 0, 4, 4); - TEST_VALIDATE_OK ("/\\\\/", NULL, 0, 4, 4); - TEST_VALIDATE_OK ("/\\\\\\//", NULL, 0, 6, 5); - TEST_VALIDATE_OK ("/\\\\\\\\/", NULL, 0, 6, 5); - TEST_VALIDATE_OK ("/\\\\\\\\\\//", NULL, 0, 8, 6); - - TEST_VALIDATE_OK ("user:/\\/", NULL, 0, 9, 4); - TEST_VALIDATE_OK ("user:/\\\\", NULL, 0, 9, 4); - TEST_VALIDATE_OK ("user:/\\\\\\/", NULL, 0, 11, 5); - TEST_VALIDATE_OK ("user:/\\\\\\\\", NULL, 0, 11, 5); - TEST_VALIDATE_OK ("user:/\\\\\\\\\\/", NULL, 0, 13, 6); - - TEST_VALIDATE_OK ("user:/\\//", NULL, 0, 9, 4); - TEST_VALIDATE_OK ("user:/\\\\/", NULL, 0, 9, 4); - TEST_VALIDATE_OK ("user:/\\\\\\//", NULL, 0, 11, 5); - TEST_VALIDATE_OK ("user:/\\\\\\\\/", NULL, 0, 11, 5); - TEST_VALIDATE_OK ("user:/\\\\\\\\\\//", NULL, 0, 13, 6); - - TEST_VALIDATE_OK ("user:/tests/plugin/\\/", NULL, 0, 22, 17); - TEST_VALIDATE_OK ("user:/tests/plugin/\\\\", NULL, 0, 22, 17); - TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\/", NULL, 0, 24, 18); - TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\\\", NULL, 0, 24, 18); - TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\\\\\/", NULL, 0, 26, 19); + TEST_VALIDATE_OK ("/", NULL); + TEST_VALIDATE_OK ("proc:/", NULL); + TEST_VALIDATE_OK ("dir:/", NULL); + TEST_VALIDATE_OK ("user:/", NULL); + TEST_VALIDATE_OK ("system:/", NULL); + TEST_VALIDATE_OK ("spec:/", NULL); + TEST_VALIDATE_OK ("meta:/", NULL); + TEST_VALIDATE_OK ("default:/", NULL); + + TEST_VALIDATE_OK ("/a", NULL); + TEST_VALIDATE_OK ("/ab", NULL); + TEST_VALIDATE_OK ("/abc", NULL); + + TEST_VALIDATE_OK ("/a", NULL); + TEST_VALIDATE_OK ("/ab", NULL); + TEST_VALIDATE_OK ("/abc", NULL); + + TEST_VALIDATE_OK ("/%", NULL); + TEST_VALIDATE_OK ("/\\%", NULL); + TEST_VALIDATE_OK ("/\\\\%", NULL); + TEST_VALIDATE_OK ("/\\\\\\\\%", NULL); + + TEST_VALIDATE_OK ("/\\/", NULL); + TEST_VALIDATE_OK ("/\\\\/", NULL); + TEST_VALIDATE_OK ("/\\\\\\/", NULL); + TEST_VALIDATE_OK ("/\\\\\\\\/", NULL); + TEST_VALIDATE_OK ("/\\\\\\\\\\/", NULL); + + TEST_VALIDATE_OK ("/\\/", NULL); + TEST_VALIDATE_OK ("/\\\\", NULL); + TEST_VALIDATE_OK ("/\\\\\\/", NULL); + TEST_VALIDATE_OK ("/\\\\\\\\", NULL); + TEST_VALIDATE_OK ("/\\\\\\\\\\/", NULL); + + TEST_VALIDATE_OK ("/\\//", NULL); + TEST_VALIDATE_OK ("/\\\\/", NULL); + TEST_VALIDATE_OK ("/\\\\\\//", NULL); + TEST_VALIDATE_OK ("/\\\\\\\\/", NULL); + TEST_VALIDATE_OK ("/\\\\\\\\\\//", NULL); + + TEST_VALIDATE_OK ("user:/\\/", NULL); + TEST_VALIDATE_OK ("user:/\\\\", NULL); + TEST_VALIDATE_OK ("user:/\\\\\\/", NULL); + TEST_VALIDATE_OK ("user:/\\\\\\\\", NULL); + TEST_VALIDATE_OK ("user:/\\\\\\\\\\/", NULL); + + TEST_VALIDATE_OK ("user:/\\//", NULL); + TEST_VALIDATE_OK ("user:/\\\\/", NULL); + TEST_VALIDATE_OK ("user:/\\\\\\//", NULL); + TEST_VALIDATE_OK ("user:/\\\\\\\\/", NULL); + TEST_VALIDATE_OK ("user:/\\\\\\\\\\//", NULL); + + TEST_VALIDATE_OK ("user:/tests/plugin/\\/", NULL); + TEST_VALIDATE_OK ("user:/tests/plugin/\\\\", NULL); + TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\/", NULL); + TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\\\", NULL); + TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\\\\\/", NULL); + + TEST_VALIDATE_OK ("user:/tests/plugin/\\//", NULL); + TEST_VALIDATE_OK ("user:/tests/plugin/\\\\/", NULL); + TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\//", NULL); + TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\\\/", NULL); + TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\\\\\//", NULL); - TEST_VALIDATE_OK ("user:/tests/plugin/\\//", NULL, 0, 22, 17); - TEST_VALIDATE_OK ("user:/tests/plugin/\\\\/", NULL, 0, 22, 17); - TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\//", NULL, 0, 24, 18); - TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\\\/", NULL, 0, 24, 18); - TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\\\\\//", NULL, 0, 26, 19); + TEST_VALIDATE_OK ("/\\//abc", NULL); + TEST_VALIDATE_OK ("/\\\\/abc", NULL); + TEST_VALIDATE_OK ("/\\\\\\//abc", NULL); + TEST_VALIDATE_OK ("/\\\\\\\\/abc", NULL); + TEST_VALIDATE_OK ("/\\\\\\\\\\//abc", NULL); - TEST_VALIDATE_OK ("/\\//abc", NULL, 0, 8, 8); - TEST_VALIDATE_OK ("/\\\\/abc", NULL, 0, 8, 8); - TEST_VALIDATE_OK ("/\\\\\\//abc", NULL, 0, 10, 9); - TEST_VALIDATE_OK ("/\\\\\\\\/abc", NULL, 0, 10, 9); - TEST_VALIDATE_OK ("/\\\\\\\\\\//abc", NULL, 0, 12, 10); + TEST_VALIDATE_OK ("user:/\\//abc", NULL); + TEST_VALIDATE_OK ("user:/\\\\/abc", NULL); + TEST_VALIDATE_OK ("user:/\\\\\\//abc", NULL); + TEST_VALIDATE_OK ("user:/\\\\\\\\/abc", NULL); + TEST_VALIDATE_OK ("user:/\\\\\\\\\\//abc", NULL); - TEST_VALIDATE_OK ("user:/\\//abc", NULL, 0, 13, 8); - TEST_VALIDATE_OK ("user:/\\\\/abc", NULL, 0, 13, 8); - TEST_VALIDATE_OK ("user:/\\\\\\//abc", NULL, 0, 15, 9); - TEST_VALIDATE_OK ("user:/\\\\\\\\/abc", NULL, 0, 15, 9); - TEST_VALIDATE_OK ("user:/\\\\\\\\\\//abc", NULL, 0, 17, 10); + TEST_VALIDATE_OK ("user:/tests/plugin/\\//abc", NULL); + TEST_VALIDATE_OK ("user:/tests/plugin/\\\\/abc", NULL); + TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\//abc", NULL); + TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\\\/abc", NULL); + TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\\\\\//abc", NULL); - TEST_VALIDATE_OK ("user:/tests/plugin/\\//abc", NULL, 0, 26, 21); - TEST_VALIDATE_OK ("user:/tests/plugin/\\\\/abc", NULL, 0, 26, 21); - TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\//abc", NULL, 0, 28, 22); - TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\\\/abc", NULL, 0, 28, 22); - TEST_VALIDATE_OK ("user:/tests/plugin/\\\\\\\\\\//abc", NULL, 0, 30, 23); + TEST_VALIDATE_OK ("/\\///", NULL); + TEST_VALIDATE_OK ("/\\/\\/", NULL); - TEST_VALIDATE_OK ("/\\///", NULL, 0, 4, 4); - TEST_VALIDATE_OK ("/\\/\\/", NULL, 0, 6, 5); + TEST_VALIDATE_OK ("/abc/def/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/def/ghi", NULL); - TEST_VALIDATE_OK ("/abc/def/ghi", NULL, 0, 13, 14); - TEST_VALIDATE_OK ("user:/abc/def/ghi", NULL, 0, 18, 14); + TEST_VALIDATE_OK ("/abc/def/ghi/", NULL); + TEST_VALIDATE_OK ("user:/abc/def/ghi/", NULL); - TEST_VALIDATE_OK ("/abc/def/ghi/", NULL, 0, 13, 14); - TEST_VALIDATE_OK ("user:/abc/def/ghi/", NULL, 0, 18, 14); + TEST_VALIDATE_OK ("/abc//def////ghi/", NULL); + TEST_VALIDATE_OK ("user://abc////def/ghi/", NULL); - TEST_VALIDATE_OK ("/abc//def////ghi/", NULL, 0, 13, 14); - TEST_VALIDATE_OK ("user://abc////def/ghi/", NULL, 0, 18, 14); + TEST_VALIDATE_OK ("/////////", NULL); + TEST_VALIDATE_OK ("user://///////", NULL); - TEST_VALIDATE_OK ("/////////", NULL, 0, 2, 3); - TEST_VALIDATE_OK ("user://///////", NULL, 0, 7, 3); + TEST_VALIDATE_OK ("/a////////", NULL); + TEST_VALIDATE_OK ("user:/a////////", NULL); - TEST_VALIDATE_OK ("/a////////", NULL, 0, 3, 4); - TEST_VALIDATE_OK ("user:/a////////", NULL, 0, 8, 4); + TEST_VALIDATE_OK ("/abc/%/def", NULL); + TEST_VALIDATE_OK ("user:/abc/%/def", NULL); - TEST_VALIDATE_OK ("/abc/%/def", NULL, 0, 11, 11); - TEST_VALIDATE_OK ("user:/abc/%/def", NULL, 0, 16, 11); + TEST_VALIDATE_OK ("/abc/d@ef/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/d@ef/ghi", NULL); - TEST_VALIDATE_OK ("/abc/d@ef/ghi", NULL, 0, 14, 15); - TEST_VALIDATE_OK ("user:/abc/d@ef/ghi", NULL, 0, 19, 15); + TEST_VALIDATE_OK ("/abc/d%ef/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/d%ef/ghi", NULL); - TEST_VALIDATE_OK ("/abc/d%ef/ghi", NULL, 0, 14, 15); - TEST_VALIDATE_OK ("user:/abc/d%ef/ghi", NULL, 0, 19, 15); + TEST_VALIDATE_OK ("/abc/.def/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/.def/ghi", NULL); - TEST_VALIDATE_OK ("/abc/.def/ghi", NULL, 0, 14, 15); - TEST_VALIDATE_OK ("user:/abc/.def/ghi", NULL, 0, 19, 15); + TEST_VALIDATE_OK ("/abc/./ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/./ghi", NULL); - TEST_VALIDATE_OK ("/abc/./ghi", NULL, 0, 9, 10); - TEST_VALIDATE_OK ("user:/abc/./ghi", NULL, 0, 14, 10); + TEST_VALIDATE_OK ("/abc/../ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/../ghi", NULL); - TEST_VALIDATE_OK ("/abc/../ghi", NULL, 0, 5, 6); - TEST_VALIDATE_OK ("user:/abc/../ghi", NULL, 0, 10, 6); + TEST_VALIDATE_OK ("/abc/.../ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/.../ghi", NULL); - TEST_VALIDATE_OK ("/abc/.../ghi", NULL, 0, 13, 14); - TEST_VALIDATE_OK ("user:/abc/.../ghi", NULL, 0, 18, 14); + TEST_VALIDATE_OK ("/abc/..../ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/..../ghi", NULL); - TEST_VALIDATE_OK ("/abc/..../ghi", NULL, 0, 14, 15); - TEST_VALIDATE_OK ("user:/abc/..../ghi", NULL, 0, 19, 15); + TEST_VALIDATE_OK ("/abc/#0/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#0/ghi", NULL); - TEST_VALIDATE_OK ("/abc/#0/ghi", NULL, 0, 12, 13); - TEST_VALIDATE_OK ("user:/abc/#0/ghi", NULL, 0, 17, 13); + TEST_VALIDATE_OK ("/abc/#1/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#1/ghi", NULL); - TEST_VALIDATE_OK ("/abc/#1/ghi", NULL, 0, 12, 13); - TEST_VALIDATE_OK ("user:/abc/#1/ghi", NULL, 0, 17, 13); + TEST_VALIDATE_OK ("/abc/#5/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#5/ghi", NULL); - TEST_VALIDATE_OK ("/abc/#5/ghi", NULL, 0, 12, 13); - TEST_VALIDATE_OK ("user:/abc/#5/ghi", NULL, 0, 17, 13); + TEST_VALIDATE_OK ("/abc/#10/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#10/ghi", NULL); - TEST_VALIDATE_OK ("/abc/#10/ghi", NULL, 0, 14, 15); - TEST_VALIDATE_OK ("user:/abc/#10/ghi", NULL, 0, 19, 15); + TEST_VALIDATE_OK ("/abc/#10000/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#10000/ghi", NULL); - TEST_VALIDATE_OK ("/abc/#10000/ghi", NULL, 0, 20, 21); - TEST_VALIDATE_OK ("user:/abc/#10000/ghi", NULL, 0, 25, 21); + TEST_VALIDATE_OK ("/abc/#9223372036854775807/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#9223372036854775807/ghi", NULL); - TEST_VALIDATE_OK ("/abc/#9223372036854775807/ghi", NULL, 0, 48, 49); - TEST_VALIDATE_OK ("user:/abc/#9223372036854775807/ghi", NULL, 0, 53, 49); + TEST_VALIDATE_OK ("/abc/#_10/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#_10/ghi", NULL); - TEST_VALIDATE_OK ("/abc/#_10/ghi", NULL, 0, 14, 15); - TEST_VALIDATE_OK ("user:/abc/#_10/ghi", NULL, 0, 19, 15); + TEST_VALIDATE_OK ("/abc/#1/#_10", NULL); + TEST_VALIDATE_OK ("user:/abc/#1/#_10", NULL); - TEST_VALIDATE_OK ("/abc/#1/#_10", NULL, 0, 13, 14); - TEST_VALIDATE_OK ("user:/abc/#1/#_10", NULL, 0, 18, 14); + TEST_VALIDATE_OK ("/abc/#____10000/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#____10000/ghi", NULL); - TEST_VALIDATE_OK ("/abc/#____10000/ghi", NULL, 0, 20, 21); - TEST_VALIDATE_OK ("user:/abc/#____10000/ghi", NULL, 0, 25, 21); + TEST_VALIDATE_OK ("/abc/#__________________9223372036854775807/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#__________________9223372036854775807/ghi", NULL); - TEST_VALIDATE_OK ("/abc/#__________________9223372036854775807/ghi", NULL, 0, 48, 49); - TEST_VALIDATE_OK ("user:/abc/#__________________9223372036854775807/ghi", NULL, 0, 53, 49); + TEST_VALIDATE_OK ("/abc/\\%/def", NULL); + TEST_VALIDATE_OK ("user:/abc/\\%/def", NULL); - TEST_VALIDATE_OK ("/abc/\\%/def", NULL, 0, 12, 12); - TEST_VALIDATE_OK ("user:/abc/\\%/def", NULL, 0, 17, 12); + TEST_VALIDATE_OK ("/abc/\\./ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/\\./ghi", NULL); - TEST_VALIDATE_OK ("/abc/\\./ghi", NULL, 0, 12, 12); - TEST_VALIDATE_OK ("user:/abc/\\./ghi", NULL, 0, 17, 12); + TEST_VALIDATE_OK ("/abc/\\../ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/\\../ghi", NULL); - TEST_VALIDATE_OK ("/abc/\\../ghi", NULL, 0, 13, 13); - TEST_VALIDATE_OK ("user:/abc/\\../ghi", NULL, 0, 18, 13); + TEST_VALIDATE_OK ("/abc/\\#10000/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/\\#10000/ghi", NULL); - TEST_VALIDATE_OK ("/abc/\\#_10/ghi", NULL, 0, 15, 15); - TEST_VALIDATE_OK ("user:/abc/\\#_10/ghi", NULL, 0, 20, 15); + TEST_VALIDATE_OK ("/abc/\\#9223372036854775807/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/\\#9223372036854775807/ghi", NULL); - TEST_VALIDATE_OK ("/abc/\\#0/ghi", NULL, 0, 13, 13); - TEST_VALIDATE_OK ("user:/abc/\\#0/ghi", NULL, 0, 18, 13); + TEST_VALIDATE_OK ("/abc\\/def/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc\\/def/ghi", NULL); - TEST_VALIDATE_OK ("/abc/\\.def/ghi", NULL, 0, 15, 15); - TEST_VALIDATE_OK ("user:/abc/\\.def/ghi", NULL, 0, 20, 15); + TEST_VALIDATE_OK ("/abc/de\\\\f/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/de\\\\f/ghi", NULL); - TEST_VALIDATE_OK ("/abc/\\#10/ghi", NULL, 0, 14, 14); - TEST_VALIDATE_OK ("user:/abc/\\#10/ghi", NULL, 0, 19, 14); + TEST_VALIDATE_OK ("/abc/de\\\\\\\\f/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/de\\\\\\\\f/ghi", NULL); - TEST_VALIDATE_OK ("/abc/\\#01/ghi", NULL, 0, 14, 14); - TEST_VALIDATE_OK ("user:/abc/\\#01/ghi", NULL, 0, 19, 14); + TEST_VALIDATE_OK ("/abc/de\\\\\\\\\\\\f/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/de\\\\\\\\\\\\f/ghi", NULL); - TEST_VALIDATE_OK ("/abc/\\#10000/ghi", NULL, 0, 17, 17); - TEST_VALIDATE_OK ("user:/abc/\\#10000/ghi", NULL, 0, 22, 17); + TEST_VALIDATE_OK ("/abc/def/ghi\\/", NULL); + TEST_VALIDATE_OK ("user:/abc/def/ghi\\/", NULL); - TEST_VALIDATE_OK ("/abc/\\#9223372036854775807/ghi", NULL, 0, 31, 31); - TEST_VALIDATE_OK ("user:/abc/\\#9223372036854775807/ghi", NULL, 0, 36, 31); + TEST_VALIDATE_OK ("/abc/#/def", NULL); + TEST_VALIDATE_OK ("user:/abc/#/def", NULL); - TEST_VALIDATE_OK ("/abc\\/def/ghi", NULL, 0, 14, 14); - TEST_VALIDATE_OK ("user:/abc\\/def/ghi", NULL, 0, 19, 14); + TEST_VALIDATE_OK ("/abc/def/ghi/%", NULL); + TEST_VALIDATE_OK ("user:/abc/def/ghi/%", NULL); + TEST_VALIDATE_OK ("user:/abc/..", NULL); - TEST_VALIDATE_OK ("/abc/de\\\\f/ghi", NULL, 0, 15, 15); - TEST_VALIDATE_OK ("user:/abc/de\\\\f/ghi", NULL, 0, 20, 15); + TEST_VALIDATE_OK ("///////.", NULL); + TEST_VALIDATE_OK ("/.", NULL); + TEST_VALIDATE_OK ("///.////.", NULL); + TEST_VALIDATE_OK ("////.///", NULL); + TEST_VALIDATE_OK ("//.///.//.", NULL); + TEST_VALIDATE_OK ("/./a", NULL); - TEST_VALIDATE_OK ("/abc/de\\\\\\\\f/ghi", NULL, 0, 17, 16); - TEST_VALIDATE_OK ("user:/abc/de\\\\\\\\f/ghi", NULL, 0, 22, 16); + TEST_VALIDATE_OK ("/\\\\", NULL); - TEST_VALIDATE_OK ("/abc/de\\\\\\\\\\\\f/ghi", NULL, 0, 19, 17); - TEST_VALIDATE_OK ("user:/abc/de\\\\\\\\\\\\f/ghi", NULL, 0, 24, 17); + TEST_VALIDATE_OK ("/", "///////."); + TEST_VALIDATE_OK ("/.", "/"); + TEST_VALIDATE_OK ("///.////.", "/"); + TEST_VALIDATE_OK ("////.///", "/"); + TEST_VALIDATE_OK ("//.///.//.", "/"); + TEST_VALIDATE_OK ("/./a", "/"); - TEST_VALIDATE_OK ("/abc/def/ghi\\/", NULL, 0, 15, 15); - TEST_VALIDATE_OK ("user:/abc/def/ghi\\/", NULL, 0, 20, 15); + TEST_VALIDATE_OK ("", "/"); + TEST_VALIDATE_OK ("", "user:/"); - TEST_VALIDATE_OK ("/abc/\\@/def", NULL, 0, 12, 12); - TEST_VALIDATE_OK ("user:/abc/\\@/def", NULL, 0, 17, 12); + TEST_VALIDATE_OK ("", "/abc"); + TEST_VALIDATE_OK ("/", "/abc"); + TEST_VALIDATE_OK ("%", "/abc"); - TEST_VALIDATE_OK ("/abc/#/def", NULL, 0, 11, 12); - TEST_VALIDATE_OK ("user:/abc/#/def", NULL, 0, 16, 12); + TEST_VALIDATE_OK ("/abc/def/ghi", "/abc"); + TEST_VALIDATE_OK ("/abc/def/ghi/", "/abc"); + TEST_VALIDATE_OK ("/abc//def////ghi/", "/abc"); + TEST_VALIDATE_OK ("/////////", "/abc"); + TEST_VALIDATE_OK ("/abc/%/def", "/abc"); + TEST_VALIDATE_OK ("/abc/d@ef/ghi", "/abc"); + TEST_VALIDATE_OK ("/abc/.def/ghi", "/abc"); - TEST_VALIDATE_OK ("/abc/\\#def/ghi", NULL, 0, 15, 15); - TEST_VALIDATE_OK ("user:/abc/\\#def/ghi", NULL, 0, 20, 15); + TEST_VALIDATE_OK ("abc", "/"); + TEST_VALIDATE_OK ("abc", "/abc"); + TEST_VALIDATE_OK (".", "/abc"); - TEST_VALIDATE_OK ("/abc/def/ghi/%", NULL, 0, 15, 15); - TEST_VALIDATE_OK ("user:/abc/def/ghi/%", NULL, 0, 20, 15); - TEST_VALIDATE_OK ("user:/abc/..", NULL, 0, 7, 3); + TEST_VALIDATE_OK ("../abc", "/x"); + TEST_VALIDATE_OK ("../../ab/c", "/x/y"); - TEST_VALIDATE_OK ("///////.", NULL, 0, 2, 3); - TEST_VALIDATE_OK ("/.", NULL, 0, 2, 3); - TEST_VALIDATE_OK ("///.////.", NULL, 0, 2, 3); - TEST_VALIDATE_OK ("////.///", NULL, 0, 2, 3); - TEST_VALIDATE_OK ("//.///.//.", NULL, 0, 2, 3); - TEST_VALIDATE_OK ("/./a", NULL, 0, 3, 4); + TEST_VALIDATE_OK ("/..", "/abc"); + TEST_VALIDATE_OK ("..", "/abc"); + TEST_VALIDATE_OK ("/../..", "/abc/def"); + TEST_VALIDATE_OK ("../..", "/abc/def"); + TEST_VALIDATE_OK ("/def/../..", "/abc"); + TEST_VALIDATE_OK ("def/../..", "/abc"); + TEST_VALIDATE_OK ("/%/../..", "/abc"); + TEST_VALIDATE_OK ("%/../..", "/abc"); - TEST_VALIDATE_OK ("/\\\\", NULL, 0, 4, 4); - TEST_VALIDATE_OK ("/\\#0/\\#1", NULL, 0, 9, 8); + TEST_VALIDATE_OK ("/..///////////////..", "/abc/def"); - TEST_VALIDATE_OK ("///////.", "/", 3, 2, 3); - TEST_VALIDATE_OK ("/.", "/", 3, 2, 3); - TEST_VALIDATE_OK ("///.////.", "/", 3, 2, 3); - TEST_VALIDATE_OK ("////.///", "/", 3, 2, 3); - TEST_VALIDATE_OK ("//.///.//.", "/", 3, 2, 3); - TEST_VALIDATE_OK ("/./a", "/", 3, 3, 4); + TEST_VALIDATE_OK ("..", "/%"); + TEST_VALIDATE_OK ("..", "/\\/"); + TEST_VALIDATE_OK ("/\\//..", "/abc"); + TEST_VALIDATE_OK ("/\\./..", "/abc"); + TEST_VALIDATE_OK ("/a/./..", "/abc"); + TEST_VALIDATE_OK ("/\\\\\\\\\\\\/..", "/abc"); - TEST_VALIDATE_OK ("", "/", 3, 2, 3); - TEST_VALIDATE_OK ("", "user:/", 3, 7, 3); + TEST_VALIDATE_OK ("../.", "/%"); - TEST_VALIDATE_OK ("", "/abc", 6, 5, 6); - TEST_VALIDATE_OK ("/", "/abc", 6, 5, 6); - TEST_VALIDATE_OK ("%", "/abc", 6, 7, 7); + TEST_VALIDATE_OK ("/#0/..", "/"); + TEST_VALIDATE_OK ("/#10/..", "/"); + TEST_VALIDATE_OK ("/#_10/..", "/"); - TEST_VALIDATE_OK ("/abc/def/ghi", "/abc", 6, 17, 18); - TEST_VALIDATE_OK ("/abc/def/ghi/", "/abc", 6, 17, 18); - TEST_VALIDATE_OK ("/abc//def////ghi/", "/abc", 6, 17, 18); - TEST_VALIDATE_OK ("/////////", "/abc", 6, 5, 6); - TEST_VALIDATE_OK ("/abc/%/def", "/abc", 6, 15, 15); - TEST_VALIDATE_OK ("/abc/d@ef/ghi", "/abc", 6, 18, 19); - TEST_VALIDATE_OK ("/abc/.def/ghi", "/abc", 6, 18, 19); + TEST_VALIDATE_OK ("user:", "/"); + TEST_VALIDATE_OK ("user", "/"); - TEST_VALIDATE_OK ("abc", "/", 3, 5, 6); - TEST_VALIDATE_OK ("abc", "/abc", 6, 9, 10); - TEST_VALIDATE_OK (".", "/abc", 6, 5, 6); + TEST_VALIDATE_OK ("abc", "user:/"); + TEST_VALIDATE_OK ("abc", "user:/abc"); + TEST_VALIDATE_OK ("..", "user:/abc"); - TEST_VALIDATE_OK ("../abc", "/x", 4, 5, 6); - TEST_VALIDATE_OK ("../../ab/c", "/x/y", 6, 6, 7); + TEST_VALIDATE_OK ("/./../..", "/abc"); + TEST_VALIDATE_OK ("./../..", "/abc"); + TEST_VALIDATE_OK ("abc/..", "user:/"); - TEST_VALIDATE_OK ("/..", "/abc", 6, 2, 3); - TEST_VALIDATE_OK ("..", "/abc", 6, 2, 3); - TEST_VALIDATE_OK ("/../..", "/abc/def", 10, 2, 3); - TEST_VALIDATE_OK ("../..", "/abc/def", 10, 2, 3); - TEST_VALIDATE_OK ("/def/../..", "/abc", 6, 2, 3); - TEST_VALIDATE_OK ("def/../..", "/abc", 6, 2, 3); - TEST_VALIDATE_OK ("/%/../..", "/abc", 6, 2, 3); - TEST_VALIDATE_OK ("%/../..", "/abc", 6, 2, 3); + TEST_VALIDATE_OK ("/abc/%def/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/%def/ghi", NULL); - TEST_VALIDATE_OK ("/..///////////////..", "/abc/def", 10, 2, 3); + TEST_VALIDATE_OK ("/..", NULL); + TEST_VALIDATE_OK ("user:/..", NULL); + TEST_VALIDATE_OK ("/abc/../..", NULL); - TEST_VALIDATE_OK ("..", "/%", 4, 2, 3); - TEST_VALIDATE_OK ("..", "/\\/", 5, 2, 3); - TEST_VALIDATE_OK ("/\\//..", "/abc", 6, 5, 6); - TEST_VALIDATE_OK ("/\\./..", "/abc", 6, 5, 6); - TEST_VALIDATE_OK ("/a/./..", "/abc", 6, 7, 8); - TEST_VALIDATE_OK ("/\\\\\\\\\\\\/..", "/abc", 6, 5, 6); + TEST_VALIDATE_OK ("/../..", "/abc"); + TEST_VALIDATE_OK ("@", "/abc"); - TEST_VALIDATE_OK ("../.", "/%", 4, 2, 3); + TEST_VALIDATE_OK ("/abc/#92233720368547758071/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#92233720368547758071/ghi", NULL); - TEST_VALIDATE_OK ("/#0/..", "/", 3, 2, 3); - TEST_VALIDATE_OK ("/#10/..", "/", 3, 2, 3); - TEST_VALIDATE_OK ("/#_10/..", "/", 3, 2, 3); - TEST_VALIDATE_OK ("/\\#0/..", "/", 3, 2, 3); + TEST_VALIDATE_OK ("/abc/#9223372036854775808/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#9223372036854775808/ghi", NULL); - TEST_VALIDATE_OK ("user:", "/", 3, 7, 8); - TEST_VALIDATE_OK ("user", "/", 3, 6, 7); + TEST_VALIDATE_OK ("/abc/#__________________9223372036854775808/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#__________________9223372036854775808/ghi", NULL); - TEST_VALIDATE_OK ("abc", "user:/", 3, 10, 6); - TEST_VALIDATE_OK ("abc", "user:/abc", 6, 14, 10); - TEST_VALIDATE_OK ("..", "user:/abc", 6, 7, 3); + TEST_VALIDATE_OK ("/abc/#01/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#01/ghi", NULL); - TEST_VALIDATE_OK ("/./../..", "/abc", 6, 2, 3); - TEST_VALIDATE_OK ("./../..", "/abc", 6, 2, 3); - TEST_VALIDATE_OK ("abc/..", "user:/", 3, 7, 3); + TEST_VALIDATE_OK ("/abc/#__10/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#__10/ghi", NULL); - TEST_VALIDATE_OK ("/abc/%def/ghi", NULL, 0, 14, 15); - TEST_VALIDATE_OK ("user:/abc/%def/ghi", NULL, 0, 19, 15); + TEST_VALIDATE_OK ("/abc/#_100/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#_100/ghi", NULL); - succeed_if (!elektraKeyNameValidate (NULL, NULL, NULL, NULL), "(NULL) SHOULD NOT BE a valid key name"); + TEST_VALIDATE_OK ("/abc/#___10/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/#___10/ghi", NULL); - TEST_VALIDATE_ERROR ("", NULL, 0); - TEST_VALIDATE_ERROR ("user/", NULL, 0); - TEST_VALIDATE_ERROR ("user:", NULL, 0); - TEST_VALIDATE_ERROR ("user", NULL, 0); + TEST_VALIDATE_OK ("/abc/@/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/@/ghi", NULL); - TEST_VALIDATE_ERROR ("/\\", NULL, 0); - TEST_VALIDATE_ERROR ("/\\\\\\", NULL, 0); + TEST_VALIDATE_OK ("/abc/@def/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/@def/ghi", NULL); - TEST_VALIDATE_ERROR ("user:abc:/", NULL, 0); - TEST_VALIDATE_ERROR ("abc:/", NULL, 0); - TEST_VALIDATE_ERROR ("abc", NULL, 0); + TEST_VALIDATE_OK ("/abc/\\#10/ghi", NULL); + TEST_VALIDATE_OK ("user:/abc/\\#10/ghi", NULL); - TEST_VALIDATE_ERROR ("/..", NULL, 0); - TEST_VALIDATE_ERROR ("user:/..", NULL, 0); - TEST_VALIDATE_ERROR ("/abc/../..", NULL, 0); + TEST_VALIDATE_OK ("/./../../..", "/abc"); + TEST_VALIDATE_OK ("./../../..", "/abc"); - TEST_VALIDATE_ERROR ("/../..", "/abc", 6); - TEST_VALIDATE_ERROR ("@", "/abc", 6); + TEST_VALIDATE_OK ("..", "/"); + TEST_VALIDATE_OK ("../..", "/a\\/b"); + TEST_VALIDATE_OK ("..", "user:/"); - TEST_VALIDATE_ERROR ("/abc/#92233720368547758071/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/#92233720368547758071/ghi", NULL, 0); + TEST_VALIDATE_OK ("../user", "user:/"); + TEST_VALIDATE_OK ("../../../../../../..//user", "/much/more/level/1/2/3"); + TEST_VALIDATE_OK ("..///../../../../../../..//user", "/much/more/level/1/2/3"); + TEST_VALIDATE_OK ("..///../../..////../../../..//user", "/much/more/level/1/2/3"); + TEST_VALIDATE_OK ("../../....///../../..////../../../..//user", "/much/more/level/1/2/3"); - TEST_VALIDATE_ERROR ("/abc/#9223372036854775808/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/#9223372036854775808/ghi", NULL, 0); + succeed_if (!elektraKeyNameValidate (NULL, true), "(NULL) SHOULD NOT BE a valid complete key name"); - TEST_VALIDATE_ERROR ("/abc/#__________________9223372036854775808/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/#__________________9223372036854775808/ghi", NULL, 0); + TEST_VALIDATE_ERROR ("", NULL); + TEST_VALIDATE_ERROR ("user/", NULL); + TEST_VALIDATE_ERROR ("user:", NULL); + TEST_VALIDATE_ERROR ("user", NULL); - TEST_VALIDATE_ERROR ("/abc/#01/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/#01/ghi", NULL, 0); + TEST_VALIDATE_ERROR ("/\\", NULL); + TEST_VALIDATE_ERROR ("/\\\\\\", NULL); - TEST_VALIDATE_ERROR ("/abc/#__10/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/#__10/ghi", NULL, 0); + TEST_VALIDATE_ERROR ("user:abc:/", NULL); + TEST_VALIDATE_ERROR ("abc:/", NULL); + TEST_VALIDATE_ERROR ("abc", NULL); - TEST_VALIDATE_ERROR ("/abc/#_100/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/#_100/ghi", NULL, 0); + TEST_VALIDATE_ERROR ("/abc/\\def/ghi", NULL); + TEST_VALIDATE_ERROR ("user:/abc/\\def/ghi", NULL); - TEST_VALIDATE_ERROR ("/abc/#___10/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/#___10/ghi", NULL, 0); + TEST_VALIDATE_ERROR ("/abc/d\\.ef/ghi", NULL); + TEST_VALIDATE_ERROR ("user:/abc/d\\.ef/ghi", NULL); - TEST_VALIDATE_ERROR ("/abc/\\def/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/\\def/ghi", NULL, 0); + TEST_VALIDATE_ERROR ("/abc/d\\#ef/ghi", NULL); + TEST_VALIDATE_ERROR ("user:/abc/d\\#ef/ghi", NULL); - TEST_VALIDATE_ERROR ("/abc/d\\.ef/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/d\\.ef/ghi", NULL, 0); + TEST_VALIDATE_ERROR ("/abc/d\\%ef/ghi", NULL); + TEST_VALIDATE_ERROR ("user:/abc/d\\%ef/ghi", NULL); - TEST_VALIDATE_ERROR ("/abc/d\\#ef/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/d\\#ef/ghi", NULL, 0); + TEST_VALIDATE_ERROR ("/abc/d\\@ef/ghi", NULL); + TEST_VALIDATE_ERROR ("user:/abc/d\\@ef/ghi", NULL); - TEST_VALIDATE_ERROR ("/abc/d\\%ef/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/d\\%ef/ghi", NULL, 0); + TEST_VALIDATE_ERROR ("/abc/\\def/ghi", NULL); + TEST_VALIDATE_ERROR ("user:/abc/\\def/ghi", NULL); - TEST_VALIDATE_ERROR ("/abc/d\\@ef/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/d\\@ef/ghi", NULL, 0); + TEST_VALIDATE_ERROR ("/\\\\\\%", NULL); + TEST_VALIDATE_ERROR ("/\\\\\\\\\\%", NULL); - TEST_VALIDATE_ERROR ("/abc/@/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/@/ghi", NULL, 0); + TEST_VALIDATE_ERROR ("/abc/\\#_10/ghi", NULL); + TEST_VALIDATE_ERROR ("user:/abc/\\#_10/ghi", NULL); - TEST_VALIDATE_ERROR ("/abc/@def/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/@def/ghi", NULL, 0); + TEST_VALIDATE_ERROR ("/abc/\\#0/ghi", NULL); + TEST_VALIDATE_ERROR ("user:/abc/\\#0/ghi", NULL); - TEST_VALIDATE_ERROR ("/abc/\\def/ghi", NULL, 0); - TEST_VALIDATE_ERROR ("user:/abc/\\def/ghi", NULL, 0); + TEST_VALIDATE_ERROR ("/abc/\\.def/ghi", NULL); + TEST_VALIDATE_ERROR ("user:/abc/\\.def/ghi", NULL); - TEST_VALIDATE_ERROR ("/./../../..", "/abc", 6); - TEST_VALIDATE_ERROR ("./../../..", "/abc", 6); + TEST_VALIDATE_ERROR ("/abc/\\#01/ghi", NULL); + TEST_VALIDATE_ERROR ("user:/abc/\\#01/ghi", NULL); - TEST_VALIDATE_ERROR ("..", "/", 3); - TEST_VALIDATE_ERROR ("../..", "/a\\/b", 6); - TEST_VALIDATE_ERROR ("..", "user:/", 3); + TEST_VALIDATE_ERROR ("/abc/\\@/def", NULL); + TEST_VALIDATE_ERROR ("user:/abc/\\@/def", NULL); - TEST_VALIDATE_ERROR ("../user", "user:/", 3); - TEST_VALIDATE_ERROR ("../../../../../../..//user", "/much/more/level/1/2/3", 23); - TEST_VALIDATE_ERROR ("..///../../../../../../..//user", "/much/more/level/1/2/3", 23); - TEST_VALIDATE_ERROR ("..///../../..////../../../..//user", "/much/more/level/1/2/3", 23); - TEST_VALIDATE_ERROR ("../../....///../../..////../../../..//user", "/much/more/level/1/2/3", 23); + TEST_VALIDATE_ERROR ("/abc/\\#def/ghi", NULL); + TEST_VALIDATE_ERROR ("user:/abc/\\#def/ghi", NULL); - TEST_VALIDATE_ERROR ("/\\\\\\%", NULL, 0); - TEST_VALIDATE_ERROR ("/\\\\\\\\\\%", NULL, 0); + TEST_VALIDATE_ERROR ("/\\#0/\\#1", NULL); + TEST_VALIDATE_ERROR ("/\\#0/..", "/"); } #undef TEST_VALIDATE_OK #undef TEST_VALIDATE_ERROR -#define TEST_CANONICALIZE_OK(name, prefix, cname) \ +#define TEST_CANONICALIZE_OK(name, prefix, cname, usizeOld, usizeNew) \ do \ { \ - size_t bufLen = sizeof (prefix) > sizeof (cname) ? sizeof (prefix) : sizeof (cname); \ - char * buf = elektraMalloc (bufLen); \ - memset (buf, ' ', bufLen - 1); \ - strcpy (buf, prefix); \ - elektraKeyNameCanonicalize (name, &buf, sizeof (cname), sizeof (prefix) - 1); \ + size_t csize = prefix == NULL ? 0 : sizeof (prefix); \ + size_t usize = usizeOld; \ + char * buf = prefix == NULL ? NULL : elektraStrDup (prefix); \ + elektraKeyNameCanonicalize (name, &buf, &csize, csize, &usize); \ succeed_if_same_string (buf, cname); \ + succeed_if_fmt (csize == sizeof (cname), "'%s' + '%s': unescaped size wrong (act != exp): %zu != %zu", \ + prefix == NULL ? "" : prefix, name, csize, sizeof (cname)); \ + succeed_if_fmt (usize == usizeNew, "'%s' + '%s': unescaped size wrong (act != exp): %zu != %zu", \ + prefix == NULL ? "" : prefix, name, usize, (size_t) usizeNew); \ elektraFree (buf); \ } while (0) static void test_canonicalize (void) { - TEST_CANONICALIZE_OK ("/", "", "/"); - TEST_CANONICALIZE_OK ("proc:/", "", "proc:/"); - TEST_CANONICALIZE_OK ("dir:/", "", "dir:/"); - TEST_CANONICALIZE_OK ("user:/", "", "user:/"); - TEST_CANONICALIZE_OK ("system:/", "", "system:/"); - TEST_CANONICALIZE_OK ("spec:/", "", "spec:/"); - TEST_CANONICALIZE_OK ("meta:/", "", "meta:/"); - TEST_CANONICALIZE_OK ("default:/", "", "default:/"); + TEST_CANONICALIZE_OK ("/", NULL, "/", 0, 3); + TEST_CANONICALIZE_OK ("proc:/", NULL, "proc:/", 0, 3); + TEST_CANONICALIZE_OK ("dir:/", NULL, "dir:/", 0, 3); + TEST_CANONICALIZE_OK ("user:/", NULL, "user:/", 0, 3); + TEST_CANONICALIZE_OK ("system:/", NULL, "system:/", 0, 3); + TEST_CANONICALIZE_OK ("spec:/", NULL, "spec:/", 0, 3); + TEST_CANONICALIZE_OK ("meta:/", NULL, "meta:/", 0, 3); + TEST_CANONICALIZE_OK ("default:/", NULL, "default:/", 0, 3); + + TEST_CANONICALIZE_OK ("/abc/def/ghi", NULL, "/abc/def/ghi", 0, 14); + TEST_CANONICALIZE_OK ("user:/abc/def/ghi", NULL, "user:/abc/def/ghi", 0, 14); + + TEST_CANONICALIZE_OK ("/abc/def/ghi/", NULL, "/abc/def/ghi", 0, 14); + TEST_CANONICALIZE_OK ("user:/abc/def/ghi/", NULL, "user:/abc/def/ghi", 0, 14); + + TEST_CANONICALIZE_OK ("/abc//def////ghi/", NULL, "/abc/def/ghi", 0, 14); + TEST_CANONICALIZE_OK ("user://abc////def/ghi/", NULL, "user:/abc/def/ghi", 0, 14); + + TEST_CANONICALIZE_OK ("/////////", NULL, "/", 0, 3); + TEST_CANONICALIZE_OK ("user://///////", NULL, "user:/", 0, 3); + + TEST_CANONICALIZE_OK ("/abc/%/def", NULL, "/abc/%/def", 0, 11); + TEST_CANONICALIZE_OK ("user:/abc/%/def", NULL, "user:/abc/%/def", 0, 11); - TEST_CANONICALIZE_OK ("/abc/def/ghi", "", "/abc/def/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/def/ghi", "", "user:/abc/def/ghi"); + TEST_CANONICALIZE_OK ("/abc/d@ef/ghi", NULL, "/abc/d@ef/ghi", 0, 15); + TEST_CANONICALIZE_OK ("user:/abc/d@ef/ghi", NULL, "user:/abc/d@ef/ghi", 0, 15); - TEST_CANONICALIZE_OK ("/abc/def/ghi/", "", "/abc/def/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/def/ghi/", "", "user:/abc/def/ghi"); + TEST_CANONICALIZE_OK ("/abc/.def/ghi", NULL, "/abc/.def/ghi", 0, 15); + TEST_CANONICALIZE_OK ("user:/abc/.def/ghi", NULL, "user:/abc/.def/ghi", 0, 15); - TEST_CANONICALIZE_OK ("/abc//def////ghi/", "", "/abc/def/ghi"); - TEST_CANONICALIZE_OK ("user://abc////def/ghi/", "", "user:/abc/def/ghi"); + TEST_CANONICALIZE_OK ("/abc/./ghi", NULL, "/abc/ghi", 0, 10); + TEST_CANONICALIZE_OK ("user:/abc/./ghi", NULL, "user:/abc/ghi", 0, 10); - TEST_CANONICALIZE_OK ("/////////", "", "/"); - TEST_CANONICALIZE_OK ("user://///////", "", "user:/"); + TEST_CANONICALIZE_OK ("/abc/def/../ghi", NULL, "/abc/ghi", 0, 10); + TEST_CANONICALIZE_OK ("user:/abc/def/../ghi", NULL, "user:/abc/ghi", 0, 10); - TEST_CANONICALIZE_OK ("/abc/%/def", "", "/abc/%/def"); - TEST_CANONICALIZE_OK ("user:/abc/%/def", "", "user:/abc/%/def"); + TEST_CANONICALIZE_OK ("/abc/../ghi", NULL, "/ghi", 0, 6); + TEST_CANONICALIZE_OK ("user:/abc/../ghi", NULL, "user:/ghi", 0, 6); - TEST_CANONICALIZE_OK ("/abc/d@ef/ghi", "", "/abc/d@ef/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/d@ef/ghi", "", "user:/abc/d@ef/ghi"); + TEST_CANONICALIZE_OK ("/abc/.../ghi", NULL, "/abc/.../ghi", 0, 14); + TEST_CANONICALIZE_OK ("user:/abc/.../ghi", NULL, "user:/abc/.../ghi", 0, 14); - TEST_CANONICALIZE_OK ("/abc/.def/ghi", "", "/abc/.def/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/.def/ghi", "", "user:/abc/.def/ghi"); + TEST_CANONICALIZE_OK ("/abc/..../ghi", NULL, "/abc/..../ghi", 0, 15); + TEST_CANONICALIZE_OK ("user:/abc/..../ghi", NULL, "user:/abc/..../ghi", 0, 15); - TEST_CANONICALIZE_OK ("/abc/./ghi", "", "/abc/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/./ghi", "", "user:/abc/ghi"); + TEST_CANONICALIZE_OK ("/abc/#0/ghi", NULL, "/abc/#0/ghi", 0, 13); + TEST_CANONICALIZE_OK ("user:/abc/#0/ghi", NULL, "user:/abc/#0/ghi", 0, 13); - TEST_CANONICALIZE_OK ("/abc/../ghi", "", "/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/../ghi", "", "user:/ghi"); + TEST_CANONICALIZE_OK ("/abc/#1/ghi", NULL, "/abc/#1/ghi", 0, 13); + TEST_CANONICALIZE_OK ("user:/abc/#1/ghi", NULL, "user:/abc/#1/ghi", 0, 13); - TEST_CANONICALIZE_OK ("/abc/.../ghi", "", "/abc/.../ghi"); - TEST_CANONICALIZE_OK ("user:/abc/.../ghi", "", "user:/abc/.../ghi"); + TEST_CANONICALIZE_OK ("/abc/#5/ghi", NULL, "/abc/#5/ghi", 0, 13); + TEST_CANONICALIZE_OK ("user:/abc/#5/ghi", NULL, "user:/abc/#5/ghi", 0, 13); - TEST_CANONICALIZE_OK ("/abc/..../ghi", "", "/abc/..../ghi"); - TEST_CANONICALIZE_OK ("user:/abc/..../ghi", "", "user:/abc/..../ghi"); + TEST_CANONICALIZE_OK ("/abc/#10/ghi", NULL, "/abc/#_10/ghi", 0, 15); + TEST_CANONICALIZE_OK ("user:/abc/#10/ghi", NULL, "user:/abc/#_10/ghi", 0, 15); - TEST_CANONICALIZE_OK ("/abc/#0/ghi", "", "/abc/#0/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/#0/ghi", "", "user:/abc/#0/ghi"); + TEST_CANONICALIZE_OK ("/abc/#10000/ghi", NULL, "/abc/#____10000/ghi", 0, 21); + TEST_CANONICALIZE_OK ("user:/abc/#10000/ghi", NULL, "user:/abc/#____10000/ghi", 0, 21); - TEST_CANONICALIZE_OK ("/abc/#1/ghi", "", "/abc/#1/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/#1/ghi", "", "user:/abc/#1/ghi"); + TEST_CANONICALIZE_OK ("/abc/#9223372036854775807/ghi", NULL, "/abc/#__________________9223372036854775807/ghi", 0, 49); + TEST_CANONICALIZE_OK ("user:/abc/#9223372036854775807/ghi", NULL, "user:/abc/#__________________9223372036854775807/ghi", 0, 49); - TEST_CANONICALIZE_OK ("/abc/#5/ghi", "", "/abc/#5/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/#5/ghi", "", "user:/abc/#5/ghi"); + TEST_CANONICALIZE_OK ("/abc/#_10/ghi", NULL, "/abc/#_10/ghi", 0, 15); + TEST_CANONICALIZE_OK ("user:/abc/#_10/ghi", NULL, "user:/abc/#_10/ghi", 0, 15); - TEST_CANONICALIZE_OK ("/abc/#10/ghi", "", "/abc/#_10/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/#10/ghi", "", "user:/abc/#_10/ghi"); + TEST_CANONICALIZE_OK ("/abc/#____10000/ghi", NULL, "/abc/#____10000/ghi", 0, 21); + TEST_CANONICALIZE_OK ("user:/abc/#____10000/ghi", NULL, "user:/abc/#____10000/ghi", 0, 21); - TEST_CANONICALIZE_OK ("/abc/#10000/ghi", "", "/abc/#____10000/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/#10000/ghi", "", "user:/abc/#____10000/ghi"); + TEST_CANONICALIZE_OK ("/abc/#__________________9223372036854775807/ghi", NULL, "/abc/#__________________9223372036854775807/ghi", 0, + 49); + TEST_CANONICALIZE_OK ("user:/abc/#__________________9223372036854775807/ghi", NULL, + "user:/abc/#__________________9223372036854775807/ghi", 0, 49); - TEST_CANONICALIZE_OK ("/abc/#9223372036854775807/ghi", "", "/abc/#__________________9223372036854775807/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/#9223372036854775807/ghi", "", "user:/abc/#__________________9223372036854775807/ghi"); + TEST_CANONICALIZE_OK ("/abc/#10/ghi", NULL, "/abc/#_10/ghi", 0, 15); + TEST_CANONICALIZE_OK ("user:/abc/#10/ghi", NULL, "user:/abc/#_10/ghi", 0, 15); - TEST_CANONICALIZE_OK ("/abc/#_10/ghi", "", "/abc/#_10/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/#_10/ghi", "", "user:/abc/#_10/ghi"); + TEST_CANONICALIZE_OK ("/abc/#1/#_10", NULL, "/abc/#1/#_10", 0, 14); + TEST_CANONICALIZE_OK ("user:/abc/#1/#_10", NULL, "user:/abc/#1/#_10", 0, 14); - TEST_CANONICALIZE_OK ("/abc/#____10000/ghi", "", "/abc/#____10000/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/#____10000/ghi", "", "user:/abc/#____10000/ghi"); + TEST_CANONICALIZE_OK ("/abc/\\%/def", NULL, "/abc/\\%/def", 0, 12); + TEST_CANONICALIZE_OK ("user:/abc/\\%/def", NULL, "user:/abc/\\%/def", 0, 12); - TEST_CANONICALIZE_OK ("/abc/#__________________9223372036854775807/ghi", "", "/abc/#__________________9223372036854775807/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/#__________________9223372036854775807/ghi", "", - "user:/abc/#__________________9223372036854775807/ghi"); + TEST_CANONICALIZE_OK ("/abc/\\./ghi", NULL, "/abc/\\./ghi", 0, 12); + TEST_CANONICALIZE_OK ("user:/abc/\\./ghi", NULL, "user:/abc/\\./ghi", 0, 12); - TEST_CANONICALIZE_OK ("/abc/#10/ghi", "", "/abc/#_10/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/#10/ghi", "", "user:/abc/#_10/ghi"); + TEST_CANONICALIZE_OK ("/abc/\\../ghi", NULL, "/abc/\\../ghi", 0, 13); + TEST_CANONICALIZE_OK ("user:/abc/\\../ghi", NULL, "user:/abc/\\../ghi", 0, 13); - TEST_CANONICALIZE_OK ("/abc/#1/#_10", "", "/abc/#1/#_10"); - TEST_CANONICALIZE_OK ("user:/abc/#1/#_10", "", "user:/abc/#1/#_10"); + TEST_CANONICALIZE_OK ("/abc/\\#10/ghi", NULL, "/abc/\\#10/ghi", 0, 14); + TEST_CANONICALIZE_OK ("user:/abc/\\#10/ghi", NULL, "user:/abc/\\#10/ghi", 0, 14); - TEST_CANONICALIZE_OK ("/abc/\\%/def", "", "/abc/\\%/def"); - TEST_CANONICALIZE_OK ("user:/abc/\\%/def", "", "user:/abc/\\%/def"); + TEST_CANONICALIZE_OK ("/abc/\\#10000/ghi", NULL, "/abc/\\#10000/ghi", 0, 17); + TEST_CANONICALIZE_OK ("user:/abc/\\#10000/ghi", NULL, "user:/abc/\\#10000/ghi", 0, 17); - TEST_CANONICALIZE_OK ("/abc/\\./ghi", "", "/abc/\\./ghi"); - TEST_CANONICALIZE_OK ("user:/abc/\\./ghi", "", "user:/abc/\\./ghi"); + TEST_CANONICALIZE_OK ("/abc/\\#9223372036854775807/ghi", NULL, "/abc/\\#9223372036854775807/ghi", 0, 31); + TEST_CANONICALIZE_OK ("user:/abc/\\#9223372036854775807/ghi", NULL, "user:/abc/\\#9223372036854775807/ghi", 0, 31); - TEST_CANONICALIZE_OK ("/abc/\\../ghi", "", "/abc/\\../ghi"); - TEST_CANONICALIZE_OK ("user:/abc/\\../ghi", "", "user:/abc/\\../ghi"); + TEST_CANONICALIZE_OK ("/abc\\/def/ghi", NULL, "/abc\\/def/ghi", 0, 14); + TEST_CANONICALIZE_OK ("user:/abc\\/def/ghi", NULL, "user:/abc\\/def/ghi", 0, 14); - TEST_CANONICALIZE_OK ("/abc/\\.def/ghi", "", "/abc/\\.def/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/\\.def/ghi", "", "user:/abc/\\.def/ghi"); + TEST_CANONICALIZE_OK ("/abc/de\\\\f/ghi", NULL, "/abc/de\\\\f/ghi", 0, 15); + TEST_CANONICALIZE_OK ("user:/abc/de\\\\f/ghi", NULL, "user:/abc/de\\\\f/ghi", 0, 15); - TEST_CANONICALIZE_OK ("/abc/\\#10/ghi", "", "/abc/\\#10/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/\\#10/ghi", "", "user:/abc/\\#10/ghi"); + TEST_CANONICALIZE_OK ("/abc/def/ghi\\/", NULL, "/abc/def/ghi\\/", 0, 15); + TEST_CANONICALIZE_OK ("user:/abc/def/ghi\\/", NULL, "user:/abc/def/ghi\\/", 0, 15); - TEST_CANONICALIZE_OK ("/abc/\\#10000/ghi", "", "/abc/\\#10000/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/\\#10000/ghi", "", "user:/abc/\\#10000/ghi"); + TEST_CANONICALIZE_OK ("/abc/\\@/def", NULL, "/abc/\\@/def", 0, 12); + TEST_CANONICALIZE_OK ("user:/abc/\\@/def", NULL, "user:/abc/\\@/def", 0, 12); - TEST_CANONICALIZE_OK ("/abc/\\#9223372036854775807/ghi", "", "/abc/\\#9223372036854775807/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/\\#9223372036854775807/ghi", "", "user:/abc/\\#9223372036854775807/ghi"); + TEST_CANONICALIZE_OK ("/abc/#/def", NULL, "/abc/#/def", 0, 12); + TEST_CANONICALIZE_OK ("user:/abc/#/def", NULL, "user:/abc/#/def", 0, 12); - TEST_CANONICALIZE_OK ("/abc\\/def/ghi", "", "/abc\\/def/ghi"); - TEST_CANONICALIZE_OK ("user:/abc\\/def/ghi", "", "user:/abc\\/def/ghi"); + TEST_CANONICALIZE_OK ("/abc/\\#123/ghi", NULL, "/abc/\\#123/ghi", 0, 15); + TEST_CANONICALIZE_OK ("user:/abc/\\#123/ghi", NULL, "user:/abc/\\#123/ghi", 0, 15); - TEST_CANONICALIZE_OK ("/abc/de\\\\f/ghi", "", "/abc/de\\\\f/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/de\\\\f/ghi", "", "user:/abc/de\\\\f/ghi"); + TEST_CANONICALIZE_OK ("/abc/\\#def/ghi", NULL, "/abc/\\#def/ghi", 0, 15); + TEST_CANONICALIZE_OK ("user:/abc/\\#def/ghi", NULL, "user:/abc/\\#def/ghi", 0, 15); - TEST_CANONICALIZE_OK ("/abc/def/ghi\\/", "", "/abc/def/ghi\\/"); - TEST_CANONICALIZE_OK ("user:/abc/def/ghi\\/", "", "user:/abc/def/ghi\\/"); + TEST_CANONICALIZE_OK ("", "/abc", "/abc", 6, 6); + TEST_CANONICALIZE_OK ("/", "/abc", "/abc", 6, 6); + TEST_CANONICALIZE_OK ("%", "/abc", "/abc/%", 6, 7); - TEST_CANONICALIZE_OK ("/abc/\\@/def", "", "/abc/\\@/def"); - TEST_CANONICALIZE_OK ("user:/abc/\\@/def", "", "user:/abc/\\@/def"); + TEST_CANONICALIZE_OK ("", "/", "/", 3, 3); + TEST_CANONICALIZE_OK ("/", "/", "/", 3, 3); + TEST_CANONICALIZE_OK ("%", "/", "/%", 3, 3); // FIXME: 1:1 mapping -> make illegal - TEST_CANONICALIZE_OK ("/abc/#/def", "", "/abc/#/def"); - TEST_CANONICALIZE_OK ("user:/abc/#/def", "", "user:/abc/#/def"); + TEST_CANONICALIZE_OK ("", "user:/", "user:/", 3, 3); + TEST_CANONICALIZE_OK ("/", "user:/", "user:/", 3, 3); + TEST_CANONICALIZE_OK ("%", "user:/", "user:/%", 3, 3); // FIXME: 1:1 mapping -> make illegal - TEST_CANONICALIZE_OK ("/abc/\\#123/ghi", "", "/abc/\\#123/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/\\#123/ghi", "", "user:/abc/\\#123/ghi"); + TEST_CANONICALIZE_OK ("/abc/def/ghi", "/abc", "/abc/abc/def/ghi", 6, 18); + TEST_CANONICALIZE_OK ("/abc/def/ghi/", "/abc", "/abc/abc/def/ghi", 6, 18); + TEST_CANONICALIZE_OK ("/abc//def////ghi/", "/abc", "/abc/abc/def/ghi", 6, 18); + TEST_CANONICALIZE_OK ("/////////", "/abc", "/abc", 6, 6); + TEST_CANONICALIZE_OK ("/abc/%/def", "/abc", "/abc/abc/%/def", 6, 15); + TEST_CANONICALIZE_OK ("/abc/d@ef/ghi", "/abc", "/abc/abc/d@ef/ghi", 6, 19); + TEST_CANONICALIZE_OK ("/abc/.def/ghi", "/abc", "/abc/abc/.def/ghi", 6, 19); - TEST_CANONICALIZE_OK ("/abc/\\#def/ghi", "", "/abc/\\#def/ghi"); - TEST_CANONICALIZE_OK ("user:/abc/\\#def/ghi", "", "user:/abc/\\#def/ghi"); + TEST_CANONICALIZE_OK ("abc", "/", "/abc", 3, 6); + TEST_CANONICALIZE_OK ("abc", "/abc", "/abc/abc", 6, 10); + TEST_CANONICALIZE_OK ("..", "/abc", "/", 6, 3); + TEST_CANONICALIZE_OK ("../", "/abc", "/", 6, 3); + TEST_CANONICALIZE_OK ("/../..", "/abc/def", "/", 10, 3); + TEST_CANONICALIZE_OK ("../..", "/abc/def", "/", 10, 3); - TEST_CANONICALIZE_OK ("", "/abc", "/abc"); - TEST_CANONICALIZE_OK ("/", "/abc", "/abc"); - TEST_CANONICALIZE_OK ("%", "/abc", "/abc/%"); + TEST_CANONICALIZE_OK ("user/", "/", "/user", 3, 7); + TEST_CANONICALIZE_OK ("user:", "/", "/user:", 3, 8); + TEST_CANONICALIZE_OK ("user", "/", "/user", 3, 7); - TEST_CANONICALIZE_OK ("", "/", "/"); - TEST_CANONICALIZE_OK ("/", "/", "/"); - TEST_CANONICALIZE_OK ("%", "/", "/%"); + TEST_CANONICALIZE_OK ("..", "user:/abc", "user:/", 6, 3); + TEST_CANONICALIZE_OK ("abc/..", "user:/", "user:/", 3, 3); + TEST_CANONICALIZE_OK ("user:/abc/..", NULL, "user:/", 0, 3); - TEST_CANONICALIZE_OK ("", "user:/", "user:/"); - TEST_CANONICALIZE_OK ("/", "user:/", "user:/"); - TEST_CANONICALIZE_OK ("%", "user:/", "user:/%"); + TEST_CANONICALIZE_OK ("/%", NULL, "/%", 0, 3); // FIXME: 1:1 mapping -> make illegal + TEST_CANONICALIZE_OK ("/\\%", NULL, "/\\%", 0, 4); + TEST_CANONICALIZE_OK ("/\\\\%", NULL, "/\\\\%", 0, 5); + TEST_CANONICALIZE_OK ("/\\\\\\\\%", NULL, "/\\\\\\\\%", 0, 6); - TEST_CANONICALIZE_OK ("/abc/def/ghi", "/abc", "/abc/abc/def/ghi"); - TEST_CANONICALIZE_OK ("/abc/def/ghi/", "/abc", "/abc/abc/def/ghi"); - TEST_CANONICALIZE_OK ("/abc//def////ghi/", "/abc", "/abc/abc/def/ghi"); - TEST_CANONICALIZE_OK ("/////////", "/abc", "/abc"); - TEST_CANONICALIZE_OK ("/abc/%/def", "/abc", "/abc/abc/%/def"); - TEST_CANONICALIZE_OK ("/abc/d@ef/ghi", "/abc", "/abc/abc/d@ef/ghi"); - TEST_CANONICALIZE_OK ("/abc/.def/ghi", "/abc", "/abc/abc/.def/ghi"); + TEST_CANONICALIZE_OK ("user:/%", NULL, "user:/%", 0, 3); // FIXME: 1:1 mapping -> make illegal + TEST_CANONICALIZE_OK ("user:/\\%", NULL, "user:/\\%", 0, 4); + TEST_CANONICALIZE_OK ("user:/\\\\%", NULL, "user:/\\\\%", 0, 5); + TEST_CANONICALIZE_OK ("user:/\\\\\\\\%", NULL, "user:/\\\\\\\\%", 0, 6); - TEST_CANONICALIZE_OK ("abc", "/", "/abc"); - TEST_CANONICALIZE_OK ("abc", "/abc", "/abc/abc"); - TEST_CANONICALIZE_OK ("..", "/abc", "/"); - TEST_CANONICALIZE_OK ("../", "/abc", "/"); - TEST_CANONICALIZE_OK ("/../..", "/abc/def", "/"); - TEST_CANONICALIZE_OK ("../..", "/abc/def", "/"); + TEST_CANONICALIZE_OK ("/\\/", NULL, "/\\/", 0, 4); + TEST_CANONICALIZE_OK ("/\\\\", NULL, "/\\\\", 0, 4); + TEST_CANONICALIZE_OK ("/\\\\\\/", NULL, "/\\\\\\/", 0, 5); + TEST_CANONICALIZE_OK ("/\\\\\\\\", NULL, "/\\\\\\\\", 0, 5); + TEST_CANONICALIZE_OK ("/\\\\\\\\\\/", NULL, "/\\\\\\\\\\/", 0, 6); - TEST_CANONICALIZE_OK ("user/", "/", "/user"); - TEST_CANONICALIZE_OK ("user:", "/", "/user:"); - TEST_CANONICALIZE_OK ("user", "/", "/user"); + TEST_CANONICALIZE_OK ("/\\//", NULL, "/\\/", 0, 4); + TEST_CANONICALIZE_OK ("/\\\\/", NULL, "/\\\\", 0, 4); + TEST_CANONICALIZE_OK ("/\\\\\\//", NULL, "/\\\\\\/", 0, 5); + TEST_CANONICALIZE_OK ("/\\\\\\\\/", NULL, "/\\\\\\\\", 0, 5); + TEST_CANONICALIZE_OK ("/\\\\\\\\\\//", NULL, "/\\\\\\\\\\/", 0, 6); - TEST_CANONICALIZE_OK ("..", "user:/abc", "user:/"); - TEST_CANONICALIZE_OK ("abc/..", "user:/", "user:/"); - TEST_CANONICALIZE_OK ("user:/abc/..", "", "user:/"); + TEST_CANONICALIZE_OK ("user:/\\/", NULL, "user:/\\/", 0, 4); + TEST_CANONICALIZE_OK ("user:/\\\\", NULL, "user:/\\\\", 0, 4); + TEST_CANONICALIZE_OK ("user:/\\\\\\/", NULL, "user:/\\\\\\/", 0, 5); + TEST_CANONICALIZE_OK ("user:/\\\\\\\\", NULL, "user:/\\\\\\\\", 0, 5); + TEST_CANONICALIZE_OK ("user:/\\\\\\\\\\/", NULL, "user:/\\\\\\\\\\/", 0, 6); - TEST_CANONICALIZE_OK ("/%", "", "/%"); - TEST_CANONICALIZE_OK ("/\\%", "", "/\\%"); - TEST_CANONICALIZE_OK ("/\\\\%", "", "/\\\\%"); - TEST_CANONICALIZE_OK ("/\\\\\\\\%", "", "/\\\\\\\\%"); - - TEST_CANONICALIZE_OK ("/\\/", "", "/\\/"); - TEST_CANONICALIZE_OK ("/\\\\", "", "/\\\\"); - TEST_CANONICALIZE_OK ("/\\\\\\/", "", "/\\\\\\/"); - TEST_CANONICALIZE_OK ("/\\\\\\\\", "", "/\\\\\\\\"); - TEST_CANONICALIZE_OK ("/\\\\\\\\\\/", "", "/\\\\\\\\\\/"); - - TEST_CANONICALIZE_OK ("/\\//", "", "/\\/"); - TEST_CANONICALIZE_OK ("/\\\\/", "", "/\\\\"); - TEST_CANONICALIZE_OK ("/\\\\\\//", "", "/\\\\\\/"); - TEST_CANONICALIZE_OK ("/\\\\\\\\/", "", "/\\\\\\\\"); - TEST_CANONICALIZE_OK ("/\\\\\\\\\\//", "", "/\\\\\\\\\\/"); - - TEST_CANONICALIZE_OK ("user:/\\/", "", "user:/\\/"); - TEST_CANONICALIZE_OK ("user:/\\\\", "", "user:/\\\\"); - TEST_CANONICALIZE_OK ("user:/\\\\\\/", "", "user:/\\\\\\/"); - TEST_CANONICALIZE_OK ("user:/\\\\\\\\", "", "user:/\\\\\\\\"); - TEST_CANONICALIZE_OK ("user:/\\\\\\\\\\/", "", "user:/\\\\\\\\\\/"); - - TEST_CANONICALIZE_OK ("user:/\\//", "", "user:/\\/"); - TEST_CANONICALIZE_OK ("user:/\\\\/", "", "user:/\\\\"); - TEST_CANONICALIZE_OK ("user:/\\\\\\//", "", "user:/\\\\\\/"); - TEST_CANONICALIZE_OK ("user:/\\\\\\\\/", "", "user:/\\\\\\\\"); - TEST_CANONICALIZE_OK ("user:/\\\\\\\\\\//", "", "user:/\\\\\\\\\\/"); - - TEST_CANONICALIZE_OK ("user:/tests/plugin/\\/", "", "user:/tests/plugin/\\/"); - TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\", "", "user:/tests/plugin/\\\\"); - TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\\\/", "", "user:/tests/plugin/\\\\\\/"); - TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\\\\\", "", "user:/tests/plugin/\\\\\\\\"); - TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\\\\\\\/", "", "user:/tests/plugin/\\\\\\\\\\/"); - - TEST_CANONICALIZE_OK ("user:/tests/plugin/\\//", "", "user:/tests/plugin/\\/"); - TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\/", "", "user:/tests/plugin/\\\\"); - TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\\\//", "", "user:/tests/plugin/\\\\\\/"); - TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\\\\\/", "", "user:/tests/plugin/\\\\\\\\"); - TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\\\\\\\//", "", "user:/tests/plugin/\\\\\\\\\\/"); - - TEST_CANONICALIZE_OK ("/abc/%def/ghi", "", "/abc/%def/ghi"); - TEST_CANONICALIZE_OK ("/abc/%d%ef%/ghi", "", "/abc/%d%ef%/ghi"); - TEST_CANONICALIZE_OK ("/abc/%def%/ghi", "", "/abc/%def%/ghi"); - TEST_CANONICALIZE_OK ("/abc/d%ef/ghi", "", "/abc/d%ef/ghi"); + TEST_CANONICALIZE_OK ("user:/\\//", NULL, "user:/\\/", 0, 4); + TEST_CANONICALIZE_OK ("user:/\\\\/", NULL, "user:/\\\\", 0, 4); + TEST_CANONICALIZE_OK ("user:/\\\\\\//", NULL, "user:/\\\\\\/", 0, 5); + TEST_CANONICALIZE_OK ("user:/\\\\\\\\/", NULL, "user:/\\\\\\\\", 0, 5); + TEST_CANONICALIZE_OK ("user:/\\\\\\\\\\//", NULL, "user:/\\\\\\\\\\/", 0, 6); + + TEST_CANONICALIZE_OK ("user:/tests/plugin/\\/", NULL, "user:/tests/plugin/\\/", 0, 17); + TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\", NULL, "user:/tests/plugin/\\\\", 0, 17); + TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\\\/", NULL, "user:/tests/plugin/\\\\\\/", 0, 18); + TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\\\\\", NULL, "user:/tests/plugin/\\\\\\\\", 0, 18); + TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\\\\\\\/", NULL, "user:/tests/plugin/\\\\\\\\\\/", 0, 19); + + TEST_CANONICALIZE_OK ("user:/tests/plugin/\\//", NULL, "user:/tests/plugin/\\/", 0, 17); + TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\/", NULL, "user:/tests/plugin/\\\\", 0, 17); + TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\\\//", NULL, "user:/tests/plugin/\\\\\\/", 0, 18); + TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\\\\\/", NULL, "user:/tests/plugin/\\\\\\\\", 0, 18); + TEST_CANONICALIZE_OK ("user:/tests/plugin/\\\\\\\\\\//", NULL, "user:/tests/plugin/\\\\\\\\\\/", 0, 19); + + TEST_CANONICALIZE_OK ("/abc/%def/ghi", NULL, "/abc/%def/ghi", 0, 15); + TEST_CANONICALIZE_OK ("/abc/%d%ef%/ghi", NULL, "/abc/%d%ef%/ghi", 0, 17); + TEST_CANONICALIZE_OK ("/abc/%def%/ghi", NULL, "/abc/%def%/ghi", 0, 16); + TEST_CANONICALIZE_OK ("/abc/d%ef/ghi", NULL, "/abc/d%ef/ghi", 0, 15); + + TEST_CANONICALIZE_OK ("/abc/%def/ghi", NULL, "/abc/%def/ghi", 0, 15); + TEST_CANONICALIZE_OK ("user:/abc/%def/ghi", NULL, "user:/abc/%def/ghi", 0, 15); + + TEST_CANONICALIZE_OK ("/..", NULL, "/", 0, 3); + TEST_CANONICALIZE_OK ("user:/..", NULL, "user:/", 0, 3); + TEST_CANONICALIZE_OK ("/abc/../..", NULL, "/", 0, 3); + + TEST_CANONICALIZE_OK ("/../..", "/abc", "/", 6, 3); + TEST_CANONICALIZE_OK ("@", "/abc", "/abc/@", 8, 10); + + TEST_CANONICALIZE_OK ("/abc/#92233720368547758071/ghi", NULL, "/abc/#92233720368547758071/ghi", 0, 32); + TEST_CANONICALIZE_OK ("user:/abc/#92233720368547758071/ghi", NULL, "user:/abc/#92233720368547758071/ghi", 0, 32); + + TEST_CANONICALIZE_OK ("/abc/#9223372036854775808/ghi", NULL, "/abc/#9223372036854775808/ghi", 0, 31); + TEST_CANONICALIZE_OK ("user:/abc/#9223372036854775808/ghi", NULL, "user:/abc/#9223372036854775808/ghi", 0, 31); + + TEST_CANONICALIZE_OK ("/abc/#__________________9223372036854775808/ghi", NULL, "/abc/#__________________9223372036854775808/ghi", 0, + 49); + TEST_CANONICALIZE_OK ("user:/abc/#__________________9223372036854775808/ghi", NULL, + "user:/abc/#__________________9223372036854775808/ghi", 0, 49); + + TEST_CANONICALIZE_OK ("/abc/#01/ghi", NULL, "/abc/#01/ghi", 0, 14); + TEST_CANONICALIZE_OK ("user:/abc/#01/ghi", NULL, "user:/abc/#01/ghi", 0, 14); + + TEST_CANONICALIZE_OK ("/abc/#__10/ghi", NULL, "/abc/#__10/ghi", 0, 16); + TEST_CANONICALIZE_OK ("user:/abc/#__10/ghi", NULL, "user:/abc/#__10/ghi", 0, 16); + + TEST_CANONICALIZE_OK ("/abc/#_100/ghi", NULL, "/abc/#_100/ghi", 0, 16); + TEST_CANONICALIZE_OK ("user:/abc/#_100/ghi", NULL, "user:/abc/#_100/ghi", 0, 16); + + TEST_CANONICALIZE_OK ("/abc/#___10/ghi", NULL, "/abc/#___10/ghi", 0, 17); + TEST_CANONICALIZE_OK ("user:/abc/#___10/ghi", NULL, "user:/abc/#___10/ghi", 0, 17); + + TEST_CANONICALIZE_OK ("/abc/@/ghi", NULL, "/abc/@/ghi", 0, 12); + TEST_CANONICALIZE_OK ("user:/abc/@/ghi", NULL, "user:/abc/@/ghi", 0, 12); + + TEST_CANONICALIZE_OK ("/abc/@def/ghi", NULL, "/abc/@def/ghi", 0, 15); + TEST_CANONICALIZE_OK ("user:/abc/@def/ghi", NULL, "user:/abc/@def/ghi", 0, 15); + + TEST_CANONICALIZE_OK ("/abc/\\#10/ghi", NULL, "/abc/\\#10/ghi", 0, 14); + TEST_CANONICALIZE_OK ("user:/abc/\\#10/ghi", NULL, "user:/abc/\\#10/ghi", 0, 14); + + TEST_CANONICALIZE_OK ("/./../../..", "/abc", "/", 6, 3); + TEST_CANONICALIZE_OK ("./../../..", "/abc", "/", 6, 3); + + TEST_CANONICALIZE_OK ("..", "/", "/", 3, 3); + TEST_CANONICALIZE_OK ("../..", "/a\\/b", "/", 6, 3); + TEST_CANONICALIZE_OK ("..", "user:/", "user:/", 3, 3); + + TEST_CANONICALIZE_OK ("../user", "user:/", "user:/user", 3, 7); + TEST_CANONICALIZE_OK ("../../../../../../..//user", "/much/more/level/1/2/3", "/user", 24, 7); + TEST_CANONICALIZE_OK ("..///../../../../../../..//user", "/much/more/level/1/2/3", "/user", 24, 7); + TEST_CANONICALIZE_OK ("..///../../..////../../../..//user", "/much/more/level/1/2/3", "/user", 24, 7); + TEST_CANONICALIZE_OK ("../../....///../../..////../../../..//user", "/much/more/level/1/2/3", "/user", 24, 7); } #undef TEST_CANONICALIZE_OK @@ -660,7 +713,7 @@ static const char * keyNsNames[] = { "KEY_NS_NONE", "KEY_NS_CASCADING", "KEY_NS_ { \ char buffer[sizeof (uname) + 2]; \ char * buf = buffer; \ - elektraKeyNameUnescape (name, &buf); \ + elektraKeyNameUnescape (name, buf); \ char expected[sizeof (uname) + 2]; \ expected[0] = ns; \ memcpy (expected + 1, uname, sizeof (uname) - 1); \ @@ -826,15 +879,16 @@ static void test_escapePart (void) TEST_ESCAPE_PART_OK ("/def", "\\/def"); TEST_ESCAPE_PART_OK ("de\\f", "de\\\\f"); TEST_ESCAPE_PART_OK ("def/", "def\\/"); - TEST_ESCAPE_PART_OK ("@", "\\@"); + TEST_ESCAPE_PART_OK ("@", "@"); TEST_ESCAPE_PART_OK ("#", "#"); - TEST_ESCAPE_PART_OK ("#def", "\\#def"); + TEST_ESCAPE_PART_OK ("#def", "#def"); TEST_ESCAPE_PART_OK ("#123", "\\#123"); - TEST_ESCAPE_PART_OK ("#__10", "\\#__10"); - TEST_ESCAPE_PART_OK ("#_100", "\\#_100"); - TEST_ESCAPE_PART_OK ("#01", "\\#01"); - TEST_ESCAPE_PART_OK ("#9223372036854775808", "\\#9223372036854775808"); - TEST_ESCAPE_PART_OK ("#92233720368547758071", "\\#92233720368547758071"); + TEST_ESCAPE_PART_OK ("#__10", "#__10"); + TEST_ESCAPE_PART_OK ("#_100", "#_100"); + TEST_ESCAPE_PART_OK ("#01", "#01"); + TEST_ESCAPE_PART_OK ("#9223372036854775807", "\\#9223372036854775807"); + TEST_ESCAPE_PART_OK ("#9223372036854775808", "#9223372036854775808"); + TEST_ESCAPE_PART_OK ("#92233720368547758071", "#92233720368547758071"); TEST_ESCAPE_PART_OK ("d/f", "d\\/f"); TEST_ESCAPE_PART_OK ("user:", "user:"); TEST_ESCAPE_PART_OK ("d..f", "d..f"); diff --git a/tests/ctest/test_mount.c b/tests/ctest/test_mount.c index 5b9a8812f68..2bbc3e6c627 100644 --- a/tests/ctest/test_mount.c +++ b/tests/ctest/test_mount.c @@ -158,36 +158,35 @@ static void test_simple (void) KeySet * set_simple (void) { - return ksNew ( - 50, keyNew ("system:/elektra/mountpoints/simple", KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/anything", KEY_VALUE, "backend", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/more", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/more/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/more/config/below", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/path", KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/errorplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/errorplugins/\\#1" KDB_DEFAULT_STORAGE, KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/getplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE, KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/anything", KEY_VALUE, "plugin", - KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/more", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/more/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/more/config/below", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/path", KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user:/tests/backend/simple", KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/setplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/setplugins/\\#1" KDB_DEFAULT_STORAGE, KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/errorplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/errorplugins/\\#1" KDB_DEFAULT_STORAGE, KEY_END), KS_END); + return ksNew (50, keyNew ("system:/elektra/mountpoints/simple", KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/anything", KEY_VALUE, "backend", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/more", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/more/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/more/config/below", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/path", KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/errorplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/errorplugins/#1" KDB_DEFAULT_STORAGE, KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/getplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE, KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/anything", KEY_VALUE, + "plugin", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more/config/below", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/path", KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user:/tests/backend/simple", KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/setplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/setplugins/#1" KDB_DEFAULT_STORAGE, KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/errorplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/errorplugins/#1" KDB_DEFAULT_STORAGE, KEY_END), KS_END); } @@ -250,56 +249,55 @@ static void test_simpletrie (void) KeySet * set_two (void) { - return ksNew ( - 50, keyNew ("system:/elektra/mountpoints", KEY_END), keyNew ("system:/elektra/mountpoints/simple", KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/anything", KEY_VALUE, "backend", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/more", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/more/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/more/config/below", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/config/path", KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/getplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE, KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/anything", KEY_VALUE, "plugin", - KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/more", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/more/config", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/more/config/below", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/path", KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user:/tests/backend/simple", KEY_END), - - keyNew ("system:/elektra/mountpoints/simple/setplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/simple/setplugins/\\#1" KDB_DEFAULT_STORAGE, KEY_END), - - - keyNew ("system:/elektra/mountpoints/two", KEY_END), - - keyNew ("system:/elektra/mountpoints/two/config", KEY_END), - keyNew ("system:/elektra/mountpoints/two/config/anything", KEY_VALUE, "backend", KEY_END), - keyNew ("system:/elektra/mountpoints/two/config/more", KEY_END), - keyNew ("system:/elektra/mountpoints/two/config/more/config", KEY_END), - keyNew ("system:/elektra/mountpoints/two/config/more/config/below", KEY_END), - keyNew ("system:/elektra/mountpoints/two/config/path", KEY_END), - - keyNew ("system:/elektra/mountpoints/two/getplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/two/getplugins/\\#1" KDB_DEFAULT_STORAGE, KEY_END), - keyNew ("system:/elektra/mountpoints/two/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config", KEY_END), - keyNew ("system:/elektra/mountpoints/two/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/anything", KEY_VALUE, "plugin", - KEY_END), - keyNew ("system:/elektra/mountpoints/two/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/more", KEY_END), - keyNew ("system:/elektra/mountpoints/two/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/more/config", KEY_END), - keyNew ("system:/elektra/mountpoints/two/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/more/config/below", KEY_END), - keyNew ("system:/elektra/mountpoints/two/getplugins/\\#1" KDB_DEFAULT_STORAGE "/config/path", KEY_END), - - keyNew ("system:/elektra/mountpoints/two/mountpoint", KEY_VALUE, "user:/tests/backend/two", KEY_END), - - keyNew ("system:/elektra/mountpoints/two/setplugins", KEY_END), - keyNew ("system:/elektra/mountpoints/two/setplugins/\\#1" KDB_DEFAULT_STORAGE, KEY_END), - keyNew ("system:/elektra/mountpoints/two/setplugins/\\#2" KDB_DEFAULT_STORAGE, KEY_END), KS_END); + return ksNew (50, keyNew ("system:/elektra/mountpoints", KEY_END), keyNew ("system:/elektra/mountpoints/simple", KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/anything", KEY_VALUE, "backend", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/more", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/more/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/more/config/below", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/config/path", KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/getplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE, KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/anything", KEY_VALUE, + "plugin", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more/config", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more/config/below", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/path", KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user:/tests/backend/simple", KEY_END), + + keyNew ("system:/elektra/mountpoints/simple/setplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/simple/setplugins/#1" KDB_DEFAULT_STORAGE, KEY_END), + + + keyNew ("system:/elektra/mountpoints/two", KEY_END), + + keyNew ("system:/elektra/mountpoints/two/config", KEY_END), + keyNew ("system:/elektra/mountpoints/two/config/anything", KEY_VALUE, "backend", KEY_END), + keyNew ("system:/elektra/mountpoints/two/config/more", KEY_END), + keyNew ("system:/elektra/mountpoints/two/config/more/config", KEY_END), + keyNew ("system:/elektra/mountpoints/two/config/more/config/below", KEY_END), + keyNew ("system:/elektra/mountpoints/two/config/path", KEY_END), + + keyNew ("system:/elektra/mountpoints/two/getplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/two/getplugins/#1" KDB_DEFAULT_STORAGE, KEY_END), + keyNew ("system:/elektra/mountpoints/two/getplugins/#1" KDB_DEFAULT_STORAGE "/config", KEY_END), + keyNew ("system:/elektra/mountpoints/two/getplugins/#1" KDB_DEFAULT_STORAGE "/config/anything", KEY_VALUE, "plugin", + KEY_END), + keyNew ("system:/elektra/mountpoints/two/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more", KEY_END), + keyNew ("system:/elektra/mountpoints/two/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more/config", KEY_END), + keyNew ("system:/elektra/mountpoints/two/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more/config/below", KEY_END), + keyNew ("system:/elektra/mountpoints/two/getplugins/#1" KDB_DEFAULT_STORAGE "/config/path", KEY_END), + + keyNew ("system:/elektra/mountpoints/two/mountpoint", KEY_VALUE, "user:/tests/backend/two", KEY_END), + + keyNew ("system:/elektra/mountpoints/two/setplugins", KEY_END), + keyNew ("system:/elektra/mountpoints/two/setplugins/#1" KDB_DEFAULT_STORAGE, KEY_END), + keyNew ("system:/elektra/mountpoints/two/setplugins/#2" KDB_DEFAULT_STORAGE, KEY_END), KS_END); } static void test_two (void) diff --git a/tests/ctest/test_plugin.c b/tests/ctest/test_plugin.c index 7702765d3ad..ba8e38c8581 100644 --- a/tests/ctest/test_plugin.c +++ b/tests/ctest/test_plugin.c @@ -12,7 +12,7 @@ static void test_process (void) { printf ("Test processing of plugin name\n"); - Key * k = keyNew ("system:/elektra/\\#0name", KEY_END); + Key * k = keyNew ("system:/elektra/#0name", KEY_END); int pluginNumber = -1; char * pluginName = 0; char * referenceName = 0; @@ -24,7 +24,7 @@ static void test_process (void) elektraFree (pluginName); pluginName = 0; - keySetName (k, "system:/e/\\#2dump"); + keySetName (k, "system:/e/#2dump"); succeed_if (elektraProcessPlugin (k, &pluginNumber, &pluginName, &referenceName, 0) == 1, "process plugin error"); succeed_if (pluginNumber == 2, "number not correct"); succeed_if_same_string (pluginName, "dump"); @@ -32,7 +32,7 @@ static void test_process (void) elektraFree (pluginName); pluginName = 0; - keySetName (k, "system:/e/\\#9default"); + keySetName (k, "system:/e/#9default"); succeed_if (elektraProcessPlugin (k, &pluginNumber, &pluginName, &referenceName, 0) == 1, "process plugin error"); succeed_if (pluginNumber == 9, "number not correct"); succeed_if_same_string (pluginName, "default"); @@ -43,10 +43,10 @@ static void test_process (void) keySetName (k, "system:/e/1default"); succeed_if (elektraProcessPlugin (k, &pluginNumber, &pluginName, &referenceName, 0) == -1, "should be error"); - keySetName (k, "system:/e/\\#xdefault"); + keySetName (k, "system:/e/#xdefault"); succeed_if (elektraProcessPlugin (k, &pluginNumber, &pluginName, &referenceName, 0) == -1, "should be error"); - keySetName (k, "system:/e/\\#1#name"); + keySetName (k, "system:/e/#1#name"); succeed_if (elektraProcessPlugin (k, &pluginNumber, &pluginName, &referenceName, 0) == 2, "process plugin error"); succeed_if (pluginNumber == 1, "number not correct"); succeed_if (pluginName == 0, "plugin name not correct"); @@ -54,7 +54,7 @@ static void test_process (void) elektraFree (referenceName); referenceName = 0; - keySetName (k, "system:/e/\\#5#dump"); + keySetName (k, "system:/e/#5#dump"); succeed_if (elektraProcessPlugin (k, &pluginNumber, &pluginName, &referenceName, 0) == 2, "process plugin error"); succeed_if (pluginNumber == 5, "number not correct"); succeed_if (pluginName == 0, "plugin name not correct"); @@ -62,7 +62,7 @@ static void test_process (void) elektraFree (referenceName); referenceName = 0; - keySetName (k, "system:/e/\\#0#very_long_name with space"); + keySetName (k, "system:/e/#0#very_long_name with space"); succeed_if (elektraProcessPlugin (k, &pluginNumber, &pluginName, &referenceName, 0) == 2, "process plugin error"); succeed_if (pluginNumber == 0, "number not correct"); succeed_if (pluginName == 0, "plugin name not correct"); @@ -70,7 +70,7 @@ static void test_process (void) elektraFree (referenceName); referenceName = 0; - keySetName (k, "system:/e/\\#1#plugname#refname#"); + keySetName (k, "system:/e/#1#plugname#refname#"); succeed_if (elektraProcessPlugin (k, &pluginNumber, &pluginName, &referenceName, 0) == 3, "process plugin error"); succeed_if (pluginNumber == 1, "number not correct"); succeed_if_same_string (pluginName, "plugname"); @@ -80,7 +80,7 @@ static void test_process (void) elektraFree (referenceName); referenceName = 0; - keySetName (k, "system:/e/\\#0#dump#dumpy#"); + keySetName (k, "system:/e/#0#dump#dumpy#"); succeed_if (elektraProcessPlugin (k, &pluginNumber, &pluginName, &referenceName, 0) == 3, "process plugin error"); succeed_if (pluginNumber == 0, "number not correct"); succeed_if_same_string (pluginName, "dump"); @@ -90,7 +90,7 @@ static void test_process (void) elektraFree (referenceName); referenceName = 0; - keySetName (k, "system:/e/\\#9#default#default#"); + keySetName (k, "system:/e/#9#default#default#"); succeed_if (elektraProcessPlugin (k, &pluginNumber, &pluginName, &referenceName, 0) == 3, "process plugin error"); succeed_if (pluginNumber == 9, "number not correct"); succeed_if_same_string (pluginName, "default"); @@ -100,7 +100,7 @@ static void test_process (void) elektraFree (referenceName); referenceName = 0; - keySetName (k, "system:/e/\\#8#a_very long name with $ sthg#also a long name_()#"); + keySetName (k, "system:/e/#8#a_very long name with $ sthg#also a long name_()#"); succeed_if (elektraProcessPlugin (k, &pluginNumber, &pluginName, &referenceName, 0) == 3, "process plugin error"); succeed_if (pluginNumber == 8, "number not correct"); succeed_if_same_string (pluginName, "a_very long name with $ sthg"); diff --git a/tests/data/data_noescape.c b/tests/data/data_noescape.c index dc04856dd28..bc35aa63740 100644 --- a/tests/data/data_noescape.c +++ b/tests/data/data_noescape.c @@ -23,7 +23,6 @@ TEST_ESCAPE_PART("a\\/b\\/c\\/d\\/e\\/f\\/g\\/h\\/j\\/k\\/l\\/m\\/n\\/o\\/p\\/q\ "a/b/c/d/e/f/g/h/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z"); TEST_NOESCAPE_PART("%", ""); -TEST_NOESCAPE_PART("\\%", "%"); TEST_NOESCAPE_PART("\\\\%", "\\%"); // TEST_NOESCAPE_PART("a\\\\\\", "a\\\\\\");