Merge pull request #27774 from shivamsn97/develop

refactor: fix for #27773 by fixing string replacement method while renaming doc
This commit is contained in:
Rushabh Mehta 2024-09-25 16:53:17 +05:30 committed by GitHub
commit b82f20fd97
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -701,12 +701,22 @@ class DocType(Document):
file_content = code.replace(old, new) # replace str with full str (js controllers)
elif fname.endswith(".py"):
file_content = code.replace(
frappe.scrub(old), frappe.scrub(new)
) # replace str with _ (py imports)
file_content = file_content.replace(
old.replace(" ", ""), new.replace(" ", "")
) # replace str (py controllers)
new_scrub = frappe.scrub(new)
new_no_space_no_hyphen = new.replace(" ", "").replace("-", "")
new_no_space = new.replace(" ", "")
old_scrub = frappe.scrub(old)
old_no_space_no_hyphen = old.replace(" ", "").replace("-", "")
old_no_space = old.replace(" ", "")
# replace in one go
file_content = re.sub(
rf"{old_scrub}|{old_no_space}|{old_no_space_no_hyphen}",
lambda x: new_scrub
if x.group() == old_scrub
else new_no_space_no_hyphen
if x.group() == old_no_space_no_hyphen
else new_no_space,
code,
)
f.write(file_content)