summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-06-26 10:18:49 +0200
committerThomas Haller <thaller@redhat.com>2020-09-29 14:36:51 +0200
commit5c50280bc600db8c38cfbfce824974cf72ef15a4 (patch)
tree285365eb4f1ba224f7d75de2d5766ba4cf84ae9e
parent7c46ff24e546e3be05d594a12e4dbfb34ecc9d9f (diff)
downloadNetworkManager-5c50280bc600db8c38cfbfce824974cf72ef15a4.tar.gz
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)
-rwxr-xr-xlibnm/generate-setting-docs.py14
1 files 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('"', '&quot;')
+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(" <property name=\"%s\" name_upper=\"%s\" type=\"%s\" default=\"%s\" description=\"%s\" />\n" %
- (prop, prop_upper, value_type, escape(default_value), escape(value_desc)))
+ outfile.write(" <property name=\"%s\" name_upper=\"%s\" type=\"%s\" default=%s description=%s />\n" %
+ (prop, prop_upper, value_type, xml_quoteattr(default_value), xml_quoteattr(value_desc)))
else:
- outfile.write(" <property name=\"%s\" name_upper=\"%s\" type=\"%s\" description=\"%s\" />\n" %
- (prop, prop_upper, value_type, escape(value_desc)))
+ outfile.write(" <property name=\"%s\" name_upper=\"%s\" type=\"%s\" description=%s />\n" %
+ (prop, prop_upper, value_type, xml_quoteattr(value_desc)))
outfile.write(" </setting>\n")