From ce8e5d79fff8bc5e0c9e9b5155d5074a1ea1c044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sun, 20 Jun 2021 14:46:17 +0200 Subject: [PATCH] _GSConverter: handle stray 'GS' in output gracefully Search the GS output stream for either "GS<" or "GS>" explicitly rather than any "GS", in order to prevent the code from wrongly matching stray "GS". This fixes a recent test regression on Gentoo where the following output seems to have been wrongly matched: **** Error 'gs' ignored -- ExtGState missing from Resources. ^^ Fixes #20472 --- lib/matplotlib/testing/compare.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py index 3957188b3e2d..242bab25cd53 100644 --- a/lib/matplotlib/testing/compare.py +++ b/lib/matplotlib/testing/compare.py @@ -124,7 +124,7 @@ def _read_until(self, terminator): raise _ConverterError buf.extend(c) if buf.endswith(terminator): - return bytes(buf[:-len(terminator)]) + return bytes(buf) class _GSConverter(_Converter): @@ -154,15 +154,16 @@ def encode_and_escape(name): + b") run flush\n") self._proc.stdin.flush() # GS> if nothing left on the stack; GS if n items left on the stack. - err = self._read_until(b"GS") - stack = self._read_until(b">") + err = self._read_until((b"GS<", b"GS>")) + stack = "" + if err.endswith(b"GS<"): + stack = self._read_until(b">") if stack or not os.path.exists(dest): - stack_size = int(stack[1:]) if stack else 0 + stack_size = int(stack[:-1]) if stack else 0 self._proc.stdin.write(b"pop\n" * stack_size) # Using the systemencoding should at least get the filenames right. raise ImageComparisonFailure( - (err + b"GS" + stack + b">") - .decode(sys.getfilesystemencoding(), "replace")) + (err + stack).decode(sys.getfilesystemencoding(), "replace")) class _SVGConverter(_Converter):