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.

(cherry picked from commit 1641cc1d03)
This commit is contained in:
Thomas Haller 2020-06-26 10:18:49 +02:00
parent c590f3c071
commit 5b7d39f8e1
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -8,6 +8,7 @@ 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
@ -179,8 +180,8 @@ def settings_sort_key(x):
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():
@ -275,11 +276,17 @@ for settingxml in settings:
default_value_as_xml = ""
if default_value is not None:
default_value_as_xml = ' default="%s"' % (escape(default_value))
default_value_as_xml = " default=%s" % (xml_quoteattr(default_value))
outfile.write(
' <property name="%s" name_upper="%s" type="%s"%s description="%s" />\n'
% (prop, prop_upper, value_type, default_value_as_xml, escape(value_desc))
' <property name="%s" name_upper="%s" type="%s"%s description=%s />\n'
% (
prop,
prop_upper,
value_type,
default_value_as_xml,
xml_quoteattr(value_desc),
)
)
outfile.write(" </setting>\n")