Skip to content

Ghidra is a software reverse engineering (SRE) framework

PyGhidra: fix extension.properties parsing of values containing '='

UnsleptArch8146224f370b
diff --git a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/version.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/version.py
index 0f70b751cf..4c013a57e2 100644
--- a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/version.py
+++ b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/version.py
@@ -79,8 +79,8 @@ class ExtensionDetails:
lines = ext_path.read_text().splitlines()
kwargs = {
key: cast(key, value)
- for key, value in map(lambda l: l.split("="), lines)
- if key in valid_fields
+ for key, sep, value in map(lambda l: l.partition("="), lines)
+ if sep and key in valid_fields
}
return cls(**kwargs)
diff --git a/Ghidra/Features/PyGhidra/src/main/py/tests/test_version.py b/Ghidra/Features/PyGhidra/src/main/py/tests/test_version.py
new file mode 100644
index 0000000000..d3a0fbe773
--- /dev/null
+++ b/Ghidra/Features/PyGhidra/src/main/py/tests/test_version.py
@@ -0,0 +1,57 @@
+## ###
+# IP: GHIDRA
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+from pathlib import Path
+
+from pyghidra.version import ExtensionDetails
+
+
+def test_extension_details_round_trip(tmp_path: Path):
+ details = ExtensionDetails(
+ name="Demo",
+ description="A normal description",
+ author="tester"
+ )
+ path = tmp_path / "extension.properties"
+ path.write_text(str(details))
+ parsed = ExtensionDetails.from_file(path)
+ assert parsed.name == details.name
+ assert parsed.description == details.description
+ assert parsed.author == details.author
+
+
+def test_extension_details_value_containing_equals(tmp_path: Path):
+ # _install_plugin writes the properties file with str(details) and
+ # _uninstall_old_plugin reads it back, so a value containing '=' must survive
+ details = ExtensionDetails(
+ name="Demo",
+ description="Parses key=value pairs",
+ author="tester"
+ )
+ path = tmp_path / "extension.properties"
+ path.write_text(str(details))
+ assert ExtensionDetails.from_file(path).description == "Parses key=value pairs"
+
+
+def test_extension_details_ignores_comments_and_blank_lines(tmp_path: Path):
+ path = tmp_path / "extension.properties"
+ path.write_text(
+ "# a comment\n"
+ "\n"
+ "name=Demo\n"
+ "description=A normal description\n"
+ "author=tester\n"
+ )
+ assert ExtensionDetails.from_file(path).name == "Demo"