Skip to content

Commit

Permalink
escape special xml characters
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo committed Jan 14, 2025
1 parent a76717b commit 62236f4
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ EntryAndConfig addEntryToConfig(String config, Path target, String displayName)
int insertIndex = config.lastIndexOf("</xbel"); //cannot be -1 due to validation; we do not match the whole end tag, since between tag name and closing bracket can be whitespaces
var adjustedConfig = config.substring(0, insertIndex) //
+ "\n" //
+ ENTRY_TEMPLATE.formatted(target.toUri(), displayName, id).indent(1) //
+ ENTRY_TEMPLATE.formatted(target.toUri(), escapeXML(displayName), id).indent(1) //
+ "\n" //
+ config.substring(insertIndex);
return new EntryAndConfig(new DolphinPlacesEntry(id), adjustedConfig);
Expand All @@ -80,6 +80,12 @@ EntryAndConfig addEntryToConfig(String config, Path target, String displayName)
}
}

private String escapeXML(String s) {
return s.replace("&","&amp;") //
.replace("<","&lt;") //
.replace(">","&gt;");
}

private class DolphinPlacesEntry extends FileConfiguredQuickAccessEntry implements QuickAccessEntry {

private final String id;
Expand Down

0 comments on commit 62236f4

Please sign in to comment.