Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "keyvi/dictionary/fsa/internal/value_store_properties.h"
#include "keyvi/dictionary/fsa/internal/value_store_types.h"
#include "keyvi/util/configuration.h"
#include "keyvi/util/msgpack_util.h"

// #define ENABLE_TRACING
#include "keyvi/dictionary/util/trace.h"
Expand Down Expand Up @@ -293,7 +294,9 @@ class StringValueStoreReader final : public IValueStoreReader {
std::string GetMsgPackedValueAsString(uint64_t fsa_value,
const compression::CompressionAlgorithm compression_algorithm =
compression::CompressionAlgorithm::NO_COMPRESSION) const override {
std::string msgpacked_value = keyvi::util::ValueToMsgPack(std::string(strings_ + fsa_value));
// GH#333: if string is valid json, parse it as msgpack for backwards-compatibility
std::string msgpacked_value = keyvi::util::JsonStringToMsgPack(
std::string(strings_ + fsa_value)); // NOLINT : fine here, we access the mmaped buffer

if (compression_algorithm == compression::CompressionAlgorithm::NO_COMPRESSION) {
return msgpacked_value;
Expand Down
14 changes: 9 additions & 5 deletions python/tests/match_object_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Usage: py.test tests

import json
import keyvi
import msgpack
from test_tools import tmp_dictionary
Expand Down Expand Up @@ -86,7 +87,7 @@ def test_boolean_attributes():
m = keyvi.Match()
bytes_key = bytes("def".encode("utf-8"))
m[bytes_key] = True
assert m[bytes_key] == True
assert m[bytes_key]


def test_start():
Expand Down Expand Up @@ -206,6 +207,7 @@ def test_get_value_string():
c.add("abc", "aaaaa")
c.add("abd", "bbbbb")
c.add("abe", "{}")
c.add("abf", json.dumps({"xyz": 42}))
with tmp_dictionary(c, "match_object_string.kv") as d:
m = d["abc"]
assert m.value == "aaaaa"
Expand All @@ -223,9 +225,11 @@ def test_get_value_string():
== "bbbbb"
)
m = d["abe"]
# gh#333: keyvi < 0.6.4 returned a dictionary instead of a string
assert m.value == "{}"
assert isinstance(m.value, str)
# gh#333: return a dictionary instead of a string
assert m.value == {}
assert isinstance(m.value, dict)
m = d["abf"]
assert m.value == {"xyz": 42}


def test_matched_string():
Expand All @@ -248,5 +252,5 @@ def test_bool_operator():
assert issubclass(w[-1].category, DeprecationWarning)
assert not m
m.end = 42
assert not m is False
assert m is not False
assert m
Loading