ragflow icon indicating copy to clipboard operation
ragflow copied to clipboard

[Question]: Unexpected Escaping of Characters (Whitespace, Hyphen, etc.) Due to re.escape() in New Version in generate.py

Open marcochang1028 opened this issue 1 year ago • 2 comments

Describe your problem

In the latest version of the code in the agent/componment/generate.py, I noticed that the usage of re.escape() was introduced in the following line: prompt = re.sub(r"{%s}" % n, re.escape(str(v)), prompt)

This results in unwanted behavior where characters like whitespace (" "), hyphen ("-"), and other symbols are unnecessarily escaped, adding additional backslashes (""). In the previous version of the code, this issue did not exist, as the line used to be: prompt = re.sub(r"{%s}" % n, str(v), prompt)

I am wondering what was the reason for adding re.escape() in the new version? Was it to address a specific issue?

marcochang1028 avatar Oct 04 '24 15:10 marcochang1028

I think it should be this:

prompt = re.sub(r"{%s}" % re.escape(n), str(v), prompt)

KevinHuSh avatar Oct 05 '24 08:10 KevinHuSh

I think it should be this:

prompt = re.sub(r"{%s}" % re.escape(n), str(v), prompt)

I have tried. It works. Thank you for your great help. I think it need to be updated in the new version.

marcochang1028 avatar Oct 07 '24 01:10 marcochang1028