diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-03-29 19:40:10 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-03-29 19:40:10 +0200 |
commit | 0df5f285e95aa12c8826747c783499f5cb0989b7 (patch) | |
tree | 577e52e637ef92f62342509e874a102c2026377c /document | |
parent | 221bf923ce3d66122ee91ed7a40a356e4c4aea3b (diff) |
Only look for = when you have fully consumed the value
Diffstat (limited to 'document')
-rw-r--r-- | document/src/tests/base/documentid_test.cpp | 18 | ||||
-rw-r--r-- | document/src/vespa/document/base/idstring.cpp | 5 |
2 files changed, 18 insertions, 5 deletions
diff --git a/document/src/tests/base/documentid_test.cpp b/document/src/tests/base/documentid_test.cpp index 62ce42c0fb6..adda311e01a 100644 --- a/document/src/tests/base/documentid_test.cpp +++ b/document/src/tests/base/documentid_test.cpp @@ -1,10 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. // Unit tests for documentid. -#include <vespa/log/log.h> -LOG_SETUP("documentid_test"); -#include <vespa/fastos/fastos.h> - #include <vespa/document/base/documentid.h> #include <vespa/vespalib/testkit/testapp.h> @@ -180,6 +176,20 @@ TEST("require that key-value pairs in id id are preserved") { EXPECT_EQUAL(id_str2, DocumentId(id_str2).toString()); } +void verifyGroupLocation(string s, string group, uint64_t location) { + DocumentId d(s); + EXPECT_TRUE(d.getScheme().hasGroup()); + EXPECT_EQUAL(s, d.toString()); + EXPECT_EQUAL(group, d.getScheme().getGroup()); + EXPECT_EQUAL(location, d.getScheme().getLocation()&0xffffffff); +} + +TEST("require that = is handled correctly in group ids") { + TEST_DO(verifyGroupLocation("id:x:foo:g=X:bar", "X", 0xb89b1202)); + TEST_DO(verifyGroupLocation("id:x:foo:g=X=:bar", "X=", 0xb61ca7e1)); + TEST_DO(verifyGroupLocation("id:x:foo:g=X=:foo", "X=", 0xb61ca7e1)); +} + TEST("require that id strings reports features (hasNumber, hasGroup)") { DocumentId none("id:ns:type::foo"); EXPECT_FALSE(none.getScheme().hasNumber()); diff --git a/document/src/vespa/document/base/idstring.cpp b/document/src/vespa/document/base/idstring.cpp index 9a62471d6e8..c2eaf96ea2e 100644 --- a/document/src/vespa/document/base/idstring.cpp +++ b/document/src/vespa/document/base/idstring.cpp @@ -322,10 +322,12 @@ IdIdString::IdIdString(const stringref & id) char key(0); string::size_type pos = 0; bool has_set_location = false; + bool hasFoundKey(false); for (string::size_type i = 0; i < key_values.size(); ++i) { - if (key_values[i] == '=') { + if (!hasFoundKey && (key_values[i] == '=')) { key = key_values[i-1]; pos = i + 1; + hasFoundKey = true; } else if (key_values[i] == ',' || i == key_values.size() - 1) { stringref value(key_values.substr(pos, i - pos + (i == key_values.size() - 1))); if (key == 'n') { @@ -341,6 +343,7 @@ IdIdString::IdIdString(const stringref & id) throw IdParseException(make_string("Illegal key '%c'", key)); } pos = i + 1; + hasFoundKey = false; } } |