fix crash in xdg-menu (#799663)

epel9
Edward Sheldrake 13 years ago committed by Miroslav Lichvar
parent 062cff3dca
commit 27345f94e7

@ -52,21 +52,24 @@ def icon_attr(entry):
return ' icon="' + iconfile + '"' return ' icon="' + iconfile + '"'
return '' return ''
def escape_utf8(s):
return escape(s.encode('utf-8', 'xmlcharrefreplace'))
def entry_name(entry): def entry_name(entry):
return escape(entry.getName().encode('utf-8', 'xmlcharrefreplace')) return escape_utf8(entry.getName())
def walk_menu(entry): def walk_menu(entry):
if isinstance(entry, xdg.Menu.Menu) and entry.Show is True: if isinstance(entry, xdg.Menu.Menu) and entry.Show is True:
print '<menu id="%s" label="%s"%s>' \ print '<menu id="%s" label="%s"%s>' \
% (entry_name(entry), % (entry_name(entry),
entry_name(entry), entry_name(entry),
escape(icon_attr(entry))) escape_utf8(icon_attr(entry)))
map(walk_menu, entry.getEntries()) map(walk_menu, entry.getEntries())
print '</menu>' print '</menu>'
elif isinstance(entry, xdg.Menu.MenuEntry) and entry.Show is True: elif isinstance(entry, xdg.Menu.MenuEntry) and entry.Show is True:
print ' <item label="%s"%s>' % \ print ' <item label="%s"%s>' % \
(entry_name(entry.DesktopEntry).replace('"', ''), (entry_name(entry.DesktopEntry).replace('"', ''),
escape(icon_attr(entry.DesktopEntry))) escape_utf8(icon_attr(entry.DesktopEntry)))
command = re.sub(' -caption "%c"| -caption %c', ' -caption "%s"' % entry_name(entry.DesktopEntry), entry.DesktopEntry.getExec()) command = re.sub(' -caption "%c"| -caption %c', ' -caption "%s"' % entry_name(entry.DesktopEntry), entry.DesktopEntry.getExec())
command = re.sub(' [^ ]*%[fFuUdDnNickvm]', '', command) command = re.sub(' [^ ]*%[fFuUdDnNickvm]', '', command)
if entry.DesktopEntry.getTerminal(): if entry.DesktopEntry.getTerminal():

Loading…
Cancel
Save