Skip to content

strip newlines from PostScript DSC comment metadata - #32501

Open
Priyank-gouda678 wants to merge 1 commit into
matplotlib:mainfrom
Priyank-gouda678:ps-dsc-metadata-newline
Open

Priyank-gouda678 wants to merge 1 commit into
matplotlib:mainfrom
Priyank-gouda678:ps-dsc-metadata-newline

Conversation

@Priyank-gouda678

@Priyank-gouda678 Priyank-gouda678 commented Oct 18, 2026 •

Copy link
Copy Markdown

PR summary

The PostScript/EPS backend writes DSC header comments as %%Key: value lines in FigureCanvasPS._print_ps. The Creator value comes from savefig(metadata=...) and Title from the output filename, and neither had CR/LF removed. A newline in such a value ends the %% comment early and leaves the remainder as its own line in the document prolog, where a PostScript interpreter (including the gs/ps2pdf distiller Matplotlib runs over its own output) treats it as code rather than a comment. The PDF and SVG backends already strip or escape the equivalent metadata; this brings PS into line by collapsing CR/LF in each DSC comment value to a space, so valid single-line values are written unchanged.

Repro on current main:

import io, matplotlib
matplotlib.use("Agg")
from matplotlib.figure import Figure
buf = io.BytesIO()
Figure().savefig(buf, format="ps",
                 metadata={"Creator": "x\nsystemdict /showpage get exec"})
print(buf.getvalue().decode("latin-1").split("%%EndComments")[0])

Before, the header carries a bare systemdict /showpage get exec line between %%Creator: and %%CreationDate:; after, it stays on the %%Creator: line.

AI Disclosure

I used AI to write the code.

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • [N/A] Plotting related features are demonstrated in an example
  • [N/A] New features and API changes have release notes
  • [N/A] Documentation complies with general and docstring guidelines

@iccir

iccir commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Hello. Please review our policy on AI and fill out the AI Disclosure with the specifics of your AI use. Thank you!

@Priyank-gouda678

Copy link
Copy Markdown
Author

Updated the AI Disclosure section in the description: I used AI to write the code.

@maaz7409

Copy link
Copy Markdown
Contributor

Updated the AI Disclosure section in the description: I used AI to write the code.

Specifics of your AI use?

@iccir

iccir commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

I'm marking this PR as Autoclose. My impression is that both the code and PR summary is AI-generated and violates our policy on AI. If this is not the case, please let me or another maintainer know.

@iccir iccir added the status: autoclose candidate PRs that are not yet ready for review and may be automatically closed in two weeks label Oct 19, 2026
@github-actions

Copy link
Copy Markdown

⏰ This pull request might be automatically closed in two weeks from now.

Thank you for your contribution to Matplotlib and for the effort you have put into this PR. This pull request does not yet meet the quality and clarity standards needed for an effective review. Project maintainers have limited time for code reviews, and our goal is to prioritize well-prepared contributions to keep Matplotlib maintainable.

Matplotlib maintainers cannot provide one-to-one guidance on this PR. However, if you ask focused, well-researched questions, a community member may be willing to help. 💬

To increase the chance of a productive review:

As the author, you are responsible for driving this PR, which entails doing necessary background research as well as presenting its context and your thought process. If you are a new contributor, or do not know how to fulfill these requirements, we recommend that you familiarize yourself with Matplotlib's development conventions or engage with the community via our Discourse or one of our meetings before submitting code.

If you substantially improve this PR within two weeks, leave a comment and a team member may remove the status: autoclose candidate label and the PR stays open. Cosmetic changes or incomplete fixes will not be sufficient. Maintainers will assess improvements on their own schedule. Please do not ping (@) maintainers.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend: ps status: autoclose candidate PRs that are not yet ready for review and may be automatically closed in two weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants