Merge pull request #27774 from shivamsn97/develop
refactor: fix for #27773 by fixing string replacement method while renaming doc
This commit is contained in:
commit
b82f20fd97
1 changed files with 16 additions and 6 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue