Skip to content

Commit 10618ee

Browse files
authored
Merge pull request #547 from opsmill/bkr-fix-hfid-double-quotes
fix improperly escaped special characters in `HFID`
2 parents e358da2 + 4ec8102 commit 10618ee

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

changelog/+escape-hfid.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixed issue with improperly escaped special characters in `hfid` fields and other string values in GraphQL mutations by implementing proper JSON-style string escaping

infrahub_sdk/graphql.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import json
34
from enum import Enum
45
from typing import Any
56

@@ -18,7 +19,9 @@ def convert_to_graphql_as_string(value: Any, convert_enum: bool = False) -> str:
1819
return convert_to_graphql_as_string(value=value.value, convert_enum=True)
1920
return value.name
2021
if isinstance(value, str):
21-
return f'"{value}"'
22+
# Use json.dumps() to properly escape the string according to JSON rules,
23+
# which are compatible with GraphQL string escaping
24+
return json.dumps(value)
2225
if isinstance(value, bool):
2326
return repr(value).lower()
2427
if isinstance(value, list):

0 commit comments

Comments
 (0)