I noticed this while using PangoCairo, but I was able to reproduce it using Cairo alone:
import cairo
with cairo.SVGSurface("output.svg", 700, 700) as surface:
context = cairo.Context(surface)
context.set_source_rgb(0, 0, 0)
context.set_font_size(25)
context.select_font_face("Arial", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
context.show_text("hello_world") # works
context.show_text("hello world") # does not work
When there is a space in the string, the SVG is malformed, and contains the line:
<image id="source-6" x="0" y="0" width="0" height="0" xlink:href="data:image/png;base64,<mask id="mask-0">