Open glennehrlich opened 1 month ago
Forgot the contents of the patch file:
glenn@ubuntu:~/tmp/sv030/test$ cat patch
[update-text-after, /root/anode[1], "foo,bar"]
glenn@ubuntu:~/tmp/sv030/test$
I don't have permission to create a pull request, but here is a patch that fixes it for me (note that this fixes the formatter, so existing "patch" files will have to be recreated before they will work):
[PATCH] fix issue #133 - writing comma separated values in DiffFormatter does not take commas in the values into account. By using the csv module to write and not just read, this is fixed.
xmldiff/formatting.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/xmldiff/formatting.py b/xmldiff/formatting.py index 640ec15..5e42fb8 100644 --- a/xmldiff/formatting.py +++ b/xmldiff/formatting.py @@ -1,8 +1,10 @@ import json import re +import io
from collections import namedtuple from copy import deepcopy +from csv import writer from lxml import etree from xmldiff.diff_match_patch import diff_match_patch from xmldiff import utils @@ -742,7 +744,11 @@ class DiffFormatter(BaseFormatter): def handle_action(self, action): action_type = type(action) method = getattr(self, "handle" + action_type.name)
return csvfile.getvalue().strip()
def _handle_DeleteAttrib(self, action): return "delete-attribute", action.node, action.name -- 2.41.0.windows.3
Things like elements or comments with commas in them will cause the csv reader used in the patch code to incorrectly parse the patch line, causing a TypeError complaining about more positional arguments than expected. Not sure what the right way to configure csvreader is for this, but it does seem that there are some options that may help with this.
Anyway, test data that's similar to one of the unit tests: