Pārlūkot izejas kodu

Fix:HTTPs component re.error: bad escape \u (#9480)

### What problem does this PR solve?

When calling HTTP to request data, if the JSON string returned by the
interface contains an unasked back slash like '\u', Python's RE module
will escape 'u' as Unicode, but there is no valid 4-digit hexadecimal
number at the end, so it will directly report an error. Error: re.
error: bad escape \ u at position 26
### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
tags/v0.20.2
xiaoyu0701 pirms 2 mēnešiem
vecāks
revīzija
7f237fee16
Revīzijas autora e-pasta adrese nav piesaistīta nevienam kontam
1 mainītis faili ar 5 papildinājumiem un 1 dzēšanām
  1. 5
    1
      agent/component/base.py

+ 5
- 1
agent/component/base.py Parādīt failu

@@ -529,8 +529,12 @@ class ComponentBase(ABC):
@staticmethod
def string_format(content: str, kv: dict[str, str]) -> str:
for n, v in kv.items():
def repl(_match, val=v):
return str(val) if val is not None else ""
content = re.sub(
r"\{%s\}" % re.escape(n), v, content
r"\{%s\}" % re.escape(n),
repl,
content
)
return content


Notiek ielāde…
Atcelt
Saglabāt