Verified Commit aef7a0a6 authored by Thomas Haller's avatar Thomas Haller

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 1641cc1d)
(cherry picked from commit 5b7d39f8)
(cherry picked from commit 5c50280b)
parent ed3f959d
......@@ -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(" <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")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment