[Bug]: `graphify export svg` writes a graph.svg that is not well-formed XML when a label contains a control character
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 72/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
graphify/export.pyで、to_svgと、to_graphmlにおける既存の_strip_xml_illegalの使用箇所を調べてください。#2897のテストの隣に、ノードラベルと凡例の制御文字を対象とする回帰テストを追加するか、既存のテストを拡張してください。対象を絞ったエクスポートテストを実行してください。完了条件は、SVG出力が整形式のXMLであり、描画されるテキストから制御文字が削除されることです。
索引モデルが issue の本文から書いたものです。
説明
Pre-flight checks
- I have checked the Troubleshooting section in the README
What happened?
A node or community label that contains a C0 control character (an ANSI escape from a pasted terminal capture, a form feed used as a section separator, a NUL) ends up in graph.svg. XML 1.0 forbids those characters, so the file is not well-formed. graphify export svg still prints graph.svg written and exits 0.
The same graph exports a well-formed graph.graphml. #2897 made to_graphml strip these characters and left to_svg out, for a reason given in #2899: to_svg does not crash, matplotlib only warns about a missing glyph and draws a box. That holds for a label without a pair of $ (between two of them, a control character can make matplotlib read invalid mathtext and to_svg raise ValueError), but the file it writes is not valid XML, and the command reports success.
Expected: a well-formed graph.svg, with the control character dropped from the drawn text, as to_graphml does.
Cause, in graphify/export.py: to_svg hands the raw node labels to nx.draw_networkx_labels and the raw community label to mpatches.Patch. With the default svg.fonttype, matplotlib's SVG backend writes each drawn string into a comment (<!-- text -->). Its comment escaping handles &, <, > and --, not control characters. _strip_xml_illegal is only called from to_graphml.
Steps to reproduce
mkdir svg-repro && cd svg-repro
printf '# Notes\n\n## Build \033[31mlog capture\033[0m\n\nSome text.\n\n## Deploy\n\nSee [[Notes]].\n' > notes.md
printf 'def helper():\n return 1\n\ndef main():\n return helper()\n' > app.py
graphify update .
graphify export svg
xmllint --noout graphify-out/graph.svg
graphify export graphml
xmllint --noout graphify-out/graph.graphml
The legend takes the same path. On a project with no control character in any heading, graphify export svg --labels labels.json with {"0": "Core \u001b[0mmodule", "1": "Other\u000cgroup"} gives the same xmllint error (<!-- Core [0mmodule (4) -->).
Error output or graph output
.../graphify/export.py:1409: UserWarning: Glyph 27 () missing from font(s) DejaVu Sans.
plt.savefig(output_path, format="svg", bbox_inches="tight",
graph.svg written - embeds in Obsidian, Notion, GitHub READMEs
graphify-out/graph.svg:513: parser error : xmlParseComment: invalid xmlChar value 27
<!-- Build [31mlog capture[0m -->
The parentheses of the warning hold the ESC character. xmllint exits 1 on graph.svg and 0 on graph.graphml. The heading becomes the node Build \x1b[31mlog capture\x1b[0m in graph.json.
Graphify version
0.9.80 (v8 @ 6478eb7)
Operating System
macOS
Python Version
3.12
Installation Method
built from source (git clone)
Additional Environment Details
uv sync --all-extras --frozen, matplotlib 3.10.9 (the uv.lock version); the same file is malformed with matplotlib 3.11.2. AST-only path (graphify update), no API key involved. Reproduced on a clean checkout of v8 at 6478eb7 (no local change).
Additional context
I have a small fix and can open a PR: pass the node labels and the legend text through _strip_xml_illegal in to_svg, with a regression test next to the #2897 tests.
- 主要言語
- Python
- スター
- 124k
- フォーク
- 11.9k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Graphify-Labs/graphify のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
Graphify-Labs/graphify#3763 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Graphify-Labs/graphify#3611 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Nix supportオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
Graphify-Labs/graphify#3193 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
Graphify-Labs/graphify#2871 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
Graphify-Labs/graphify#2865 ·
メンテナーはふだん 1 日以内に返信
Graphify-Labs/graphify の issue をすべて見る
似ている issue
-
first
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
AcademySoftwareFoundation/rmtc#54 · コメント 1 件 ·
-
feature/cohorts feature/feature-flags team/feature-flags
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
License examples/ as MIT対応中かも @PGrayCS が今日担当しました。 オープンdocumentation enhancement example good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
speedyk-005/yasbd-lib#383 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
interactions-py/interactions.py#1827 ·
-
Managed start can fail when OpenVMM reads its control capability before NVX writes it対応中かも @ppenna が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信