Skip to content

Commit c8679d2

Browse files
authored
Merge pull request #409 from aiven/fix-subject-name-escaping
Fix subject name escaping
2 parents 72779bd + ea7e972 commit c8679d2

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

karapace/schema_registry_apis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def send_schema_message(
344344
version: int,
345345
deleted: bool,
346346
):
347-
key = '{{"subject":"{}","version":{},"magic":1,"keytype":"SCHEMA"}}'.format(subject, version)
347+
key = json.dumps({"subject": subject, "version": version, "magic": 1, "keytype": "SCHEMA"}, separators=(",", ":"))
348348
if schema:
349349
valuedict = {
350350
"subject": subject,

tests/integration/test_schema.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ async def test_missing_subject_compatibility(registry_async_client: Client, trai
9292
assert "compatibilityLevel" in res.json(), res.json()
9393

9494

95+
async def test_subject_allowed_chars(registry_async_client: Client) -> None:
96+
subject_prefix = create_subject_name_factory("test_subject_allowed_chars-")()
97+
98+
for suffix in ['"', "{", ":", "}", "'"]:
99+
subject = f"{subject_prefix}{suffix}"
100+
res = await registry_async_client.post(
101+
f"subjects/{subject}/versions", json={"schema": json.dumps({"type": "string"})}
102+
)
103+
assert res.status_code == 200, f"{res} {subject}"
104+
105+
95106
@pytest.mark.parametrize("trail", ["", "/"])
96107
async def test_record_union_schema_compatibility(registry_async_client: Client, trail: str) -> None:
97108
subject = create_subject_name_factory(f"test_record_union_schema_compatibility-{trail}")()

0 commit comments

Comments
 (0)