Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[Bug]: `graphify export svg` writes a graph.svg that is not well-formed XML when a label contains a control character

Abierto Apto para principiantes
#4,241 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python

Línea de trabajo

En graphify/export.py, inspecciona to_svg y el uso existente de _strip_xml_illegal en to_graphml. Añade o amplía una prueba de regresión junto a las pruebas de #2897 que cubra los caracteres de control en las etiquetas de los nodos y en la leyenda. Ejecuta las pruebas específicas de exportación; se considera terminado cuando la salida SVG sea XML bien formado y se eliminen los caracteres de control del texto dibujado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
124k
Forks
11.9k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Graphify-Labs/graphify

Todos los issues de Graphify-Labs/graphify

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.