diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/target/path/PathPattern.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/target/path/PathPattern.java index fa2861f838..1f69e8feab 100644 --- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/target/path/PathPattern.java +++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/target/path/PathPattern.java @@ -239,6 +239,24 @@ public class PathPattern implements PathFilter { return false; } + /** + * Sanitize the given key. + * + *
+ * Because brackets {@code []} indicate an index in a path, they cannot themselves be used in an
+ * index. The first closing bracket seen is taken to end the index. We could support escaping,
+ * e.g., by "{@code \[}," but that seems a bit onerous for what little it affords. We also
+ * should not endeavor to support things like "{@code Memory[something[with][brackets]]},"
+ * because we'd still have an issue if the user's brackets are not balanced. Instead, we'll just
+ * replace the square brackets with curley braces, unless/until that turns out to be a Bad Idea.
+ *
+ * @param key the key to sanitize
+ * @return the sanitized key
+ */
+ public static String sanitizeKey(String key) {
+ return key.replace('[', '{').replace(']', '}');
+ }
+
@Override
public PathPattern applyKeys(Align align, List