Skip to content

Commit ce8e5d7

Browse files
committed
_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
1 parent 3a265b3 commit ce8e5d7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/matplotlib/testing/compare.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def _read_until(self, terminator):
124124
raise _ConverterError
125125
buf.extend(c)
126126
if buf.endswith(terminator):
127-
return bytes(buf[:-len(terminator)])
127+
return bytes(buf)
128128

129129

130130
class _GSConverter(_Converter):
@@ -154,15 +154,16 @@ def encode_and_escape(name):
154154
+ b") run flush\n")
155155
self._proc.stdin.flush()
156156
# GS> if nothing left on the stack; GS<n> if n items left on the stack.
157-
err = self._read_until(b"GS")
158-
stack = self._read_until(b">")
157+
err = self._read_until((b"GS<", b"GS>"))
158+
stack = ""
159+
if err.endswith(b"GS<"):
160+
stack = self._read_until(b">")
159161
if stack or not os.path.exists(dest):
160-
stack_size = int(stack[1:]) if stack else 0
162+
stack_size = int(stack[:-1]) if stack else 0
161163
self._proc.stdin.write(b"pop\n" * stack_size)
162164
# Using the systemencoding should at least get the filenames right.
163165
raise ImageComparisonFailure(
164-
(err + b"GS" + stack + b">")
165-
.decode(sys.getfilesystemencoding(), "replace"))
166+
(err + stack).decode(sys.getfilesystemencoding(), "replace"))
166167

167168

168169
class _SVGConverter(_Converter):

0 commit comments

Comments
 (0)