Skip to content

Commit 5e9eacc

Browse files
committed
fix xml tag matching
* use correct regex for vertical whitespace splitting * only match tag start + tag name
1 parent b999064 commit 5e9eacc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/main/java/org/cryptomator/linux/quickaccess/DolphinPlaces.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public QuickAccessService.QuickAccessEntry add(Path target, String displayName)
7676
//validate
7777
xmlValidator.validate(new StreamSource(new StringReader(placesContent)));
7878
// modify
79-
int insertIndex = placesContent.lastIndexOf("</xbel>"); //cannot be -1 due to validation
79+
int insertIndex = placesContent.lastIndexOf("</xbel"); //cannot be -1 due to validation; we do not match the end tag, since betweent tag name and closing bracket can be whitespaces
8080
try (var writer = Files.newBufferedWriter(TMP_FILE, StandardCharsets.UTF_8, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
8181
writer.write(placesContent, 0, insertIndex);
8282
writer.newLine();
@@ -126,9 +126,9 @@ public void remove() throws QuickAccessServiceException {
126126
int openingTagIndex = placesContentPart1.lastIndexOf("<bookmark href=");
127127
var contentToWrite1 = placesContentPart1.substring(0, openingTagIndex).stripTrailing();
128128

129-
int closingTagIndex = placesContent.indexOf("</bookmark>", idIndex);
130-
var part2Tmp = placesContent.substring(closingTagIndex + "</bookmark>".length()).split("\\v*", 2); //removing leading vertical whitespaces
131-
var contentToWrite2 = part2Tmp.length == 1 ? part2Tmp[0] : part2Tmp[1];
129+
int closingTagEndIndex = placesContent.indexOf('>', placesContent.indexOf("</bookmark", idIndex));
130+
var part2Tmp = placesContent.substring(closingTagEndIndex + 1).split("\\v+", 2); //removing leading vertical whitespaces, but no indentation
131+
var contentToWrite2 = part2Tmp[part2Tmp.length - 1];
132132

133133
try (var writer = Files.newBufferedWriter(TMP_FILE, StandardCharsets.UTF_8, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
134134
writer.write(contentToWrite1);

0 commit comments

Comments
 (0)