Skip to content

Commit

Permalink
Use group-separator instead of ASCII 0 (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
snazy authored Jan 9, 2024
1 parent d197ac3 commit 32d3a41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pynessie/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def to_path_string(self) -> str:
"""Convert this key to a url encoded path string."""
# false positives in pylint
# pylint: disable=E1133
return ".".join(i.replace(".", "\00") if i else "" for i in self.elements)
return ".".join(i.replace(".", "\x1d").replace("\00", "\x1d") if i else "" for i in self.elements)

@staticmethod
def from_path_string(key: str) -> "ContentKey":
Expand All @@ -179,13 +179,13 @@ def _split_key_based_on_regex(raw_key: str) -> List[str]:
regex = re.compile('"[^"]*"')

# Replace any dot that is inside double quotes with null char '\00' and remove the double quotes
key_with_null = regex.sub(lambda x: x.group(0).replace(".", "\00").replace('"', ""), raw_key)
key_with_null = regex.sub(lambda x: x.group(0).replace(".", "\x1d").replace('"', ""), raw_key)

# Split based on the dot
splitted_key = key_with_null.split(".")

# Return back the splitted elements and make sure to change back '/0' to '.'
return [i.replace("\00", ".") for i in splitted_key]
return [i.replace("\x1d", ".").replace("\00", ".") for i in splitted_key]


ContentKeySchema = desert.schema_class(ContentKey)
Expand Down
13 changes: 9 additions & 4 deletions tests/test_nessie_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@ def test_content_key_from_path_string() -> None:
"""Test ContentKey.from_path_string method."""
assert_that(ContentKey.from_path_string("a.b.c")).is_equal_to(ContentKey(["a", "b", "c"]))
assert_that(ContentKey.from_path_string("a.b.c\00d")).is_equal_to(ContentKey(["a", "b", "c.d"]))
assert_that(ContentKey.from_path_string("a.b.c\x1dd")).is_equal_to(ContentKey(["a", "b", "c.d"]))
assert_that(ContentKey.from_path_string("a\00b.c.d")).is_equal_to(ContentKey(["a.b", "c", "d"]))
assert_that(ContentKey.from_path_string("a\x1db.c.d")).is_equal_to(ContentKey(["a.b", "c", "d"]))
assert_that(ContentKey.from_path_string("a\00b.c.d\00e")).is_equal_to(ContentKey(["a.b", "c", "d.e"]))
assert_that(ContentKey.from_path_string("a\x1db.c.d\x1de")).is_equal_to(ContentKey(["a.b", "c", "d.e"]))
assert_that(ContentKey.from_path_string("a\x1db.c.d\00e")).is_equal_to(ContentKey(["a.b", "c", "d.e"]))
assert_that(ContentKey.from_path_string("a.b\00c.d")).is_equal_to(ContentKey(["a", "b.c", "d"]))
assert_that(ContentKey.from_path_string("a.b\x1dc.d")).is_equal_to(ContentKey(["a", "b.c", "d"]))


def test_content_key_to_path_string() -> None:
"""Test ContentKey.to_path_string method."""
assert_that(ContentKey(["a", "b", "c"]).to_path_string()).is_equal_to("a.b.c")
assert_that(ContentKey(["a", "b", "c.d"]).to_path_string()).is_equal_to("a.b.c\00d")
assert_that(ContentKey(["a.b", "c", "d"]).to_path_string()).is_equal_to("a\00b.c.d")
assert_that(ContentKey(["a.b", "c", "d.e"]).to_path_string()).is_equal_to("a\00b.c.d\00e")
assert_that(ContentKey(["a", "b.c", "d"]).to_path_string()).is_equal_to("a.b\00c.d")
assert_that(ContentKey(["a", "b", "c.d"]).to_path_string()).is_equal_to("a.b.c\x1dd")
assert_that(ContentKey(["a.b", "c", "d"]).to_path_string()).is_equal_to("a\x1db.c.d")
assert_that(ContentKey(["a.b", "c", "d.e"]).to_path_string()).is_equal_to("a\x1db.c.d\x1de")
assert_that(ContentKey(["a", "b.c", "d"]).to_path_string()).is_equal_to("a.b\x1dc.d")

0 comments on commit 32d3a41

Please sign in to comment.