Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fall back to regular diff in case of malformed xml #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions xmldiffs
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,28 @@ else:
return fp

def xmldiffs(file1, file2, diffargs=["-u"]):
tree = ET.parse(file1)
tmp1 = unicode_writer(NamedTemporaryFile('w'))
write_sorted(tmp1, tree.getroot())
tmp1.flush()

tree = ET.parse(file2)
tmp2 = unicode_writer(NamedTemporaryFile('w'))
write_sorted(tmp2, tree.getroot())
tmp2.flush()
try:
tree = ET.parse(file1)
tmp1 = unicode_writer(NamedTemporaryFile('w'))
write_sorted(tmp1, tree.getroot())
tmp1.flush()
actual = tmp1.name
except ET.ParseError:
actual = file1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in case the XML has errors, we simply fall back to a diff of the original files?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes!


try:
tree = ET.parse(file2)
tmp2 = unicode_writer(NamedTemporaryFile('w'))
write_sorted(tmp2, tree.getroot())
tmp2.flush()
expected = tmp2.name
except ET.ParseError:
expected = file2

args = [ "diff" ]
args += diffargs
args += [ "--label", file1, "--label", file2 ]
args += [ tmp1.name, tmp2.name ]
args += [ actual, expected ]

return subprocess.call(args)

Expand Down