Merge ~logan/software-properties:lp-2008489 into software-properties:ubuntu/master

Proposed by Logan Rosen
Status: Needs review
Proposed branch: ~logan/software-properties:lp-2008489
Merge into: software-properties:ubuntu/master
Diff against target: 48 lines (+30/-1)
2 files modified
softwareproperties/gtk/SoftwarePropertiesGtk.py (+2/-1)
tests/test_SoftwarePropertiesGtk.py (+28/-0)
Reviewer Review Type Date Requested Status
Ubuntu Core Development Team Pending
Review via email: mp+444960@code.launchpad.net
To post a comment you must log in.

Unmerged commits

99a5866... by Logan Rosen

Escape message in error dialog (LP: #2008489)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/softwareproperties/gtk/SoftwarePropertiesGtk.py b/softwareproperties/gtk/SoftwarePropertiesGtk.py
2index 0cced00..2d0db6d 100644
3--- a/softwareproperties/gtk/SoftwarePropertiesGtk.py
4+++ b/softwareproperties/gtk/SoftwarePropertiesGtk.py
5@@ -148,7 +148,8 @@ def error(parent_window, summary, msg):
6 type=Gtk.MessageType.ERROR,
7 buttons=Gtk.ButtonsType.OK,
8 message_format=None)
9- dialog.set_markup("<big><b>%s</b></big>\n\n%s" % (summary, msg))
10+ escaped_msg = GLib.markup_escape_text(msg, len(msg))
11+ dialog.set_markup("<big><b>%s</b></big>\n\n%s" % (summary, escaped_msg))
12 dialog.run()
13 dialog.destroy()
14 return False
15diff --git a/tests/test_SoftwarePropertiesGtk.py b/tests/test_SoftwarePropertiesGtk.py
16new file mode 100644
17index 0000000..ca9dd28
18--- /dev/null
19+++ b/tests/test_SoftwarePropertiesGtk.py
20@@ -0,0 +1,28 @@
21+import unittest
22+from unittest.mock import patch, MagicMock
23+
24+from gi.repository import GLib
25+
26+from softwareproperties.gtk.SoftwarePropertiesGtk import error
27+
28+
29+class SoftwarePropertiesGtkTestCase(unittest.TestCase):
30+ @patch('softwareproperties.gtk.SoftwarePropertiesGtk.Gtk')
31+ def test_error_dialog_with_escaped_markup(self, mock_gtk):
32+ # Create a dummy parent window
33+ parent_window = MagicMock()
34+
35+ # Test input values
36+ summary = "Test Summary"
37+ msg = "Test Message With <Markup/>"
38+ escaped_msg = GLib.markup_escape_text(msg, len(msg))
39+
40+ # Set up mock objects and return values
41+ mock_dialog = MagicMock()
42+ mock_gtk.MessageDialog.return_value = mock_dialog
43+
44+ # Call the function
45+ error(parent_window, summary, msg)
46+
47+ # Assert that the dialog has markup set with escaped message
48+ mock_dialog.set_markup.assert_called_once_with("<big><b>%s</b></big>\n\n%s" % (summary, escaped_msg))

Subscribers

People subscribed via source and target branches