From 5c50280bc600db8c38cfbfce824974cf72ef15a4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 26 Jun 2020 10:18:49 +0200 Subject: [PATCH] docs: fix escaping XML in "tools/generate-docs-nm-settings-docs-gir.py" The gtk-doc text that the tool receives is not XML, it's a plain text. When setting the plain text as XML attribute, we need to properly escape it. The previous XML escape code was naive, and didn't cover for a plain ampersand. [thaller@redhat.com: adjusted patch during backport from nm-1-26 to nm-1-24] (cherry picked from commit 1641cc1d03941e543da716bc68ff059c5a984f37) (cherry picked from commit 5b7d39f8e166288b999f469925710e891a50a1b1) --- libnm/generate-setting-docs.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libnm/generate-setting-docs.py b/libnm/generate-setting-docs.py index 025689ea3c..6f8a03700d 100755 --- a/libnm/generate-setting-docs.py +++ b/libnm/generate-setting-docs.py @@ -8,6 +8,8 @@ from __future__ import print_function import os import gi +import xml.sax.saxutils as saxutils + gi.require_version('GIRepository', '2.0') from gi.repository import GIRepository import argparse, datetime, re, sys @@ -163,8 +165,8 @@ def settings_sort_key(x): # always sort NMSettingConnection first return (x_prefix != "setting_connection", x_prefix); -def escape(val): - return str(val).replace('"', '"') +def xml_quoteattr(val): + return saxutils.quoteattr(str(val)) def usage(): print("Usage: %s --gir FILE --output FILE" % sys.argv[0]) @@ -256,11 +258,11 @@ for settingxml in settings: raise Exception("%s.%s needs a documentation description" % (setting.props.name, prop)) if default_value is not None: - outfile.write(" \n" % - (prop, prop_upper, value_type, escape(default_value), escape(value_desc))) + outfile.write(" \n" % + (prop, prop_upper, value_type, xml_quoteattr(default_value), xml_quoteattr(value_desc))) else: - outfile.write(" \n" % - (prop, prop_upper, value_type, escape(value_desc))) + outfile.write(" \n" % + (prop, prop_upper, value_type, xml_quoteattr(value_desc))) outfile.write(" \n")