20
20
import java .nio .file .Path ;
21
21
import java .nio .file .StandardCopyOption ;
22
22
import java .nio .file .StandardOpenOption ;
23
+ import java .util .List ;
23
24
import java .util .UUID ;
24
25
import java .util .concurrent .TimeUnit ;
25
26
import java .util .concurrent .locks .Lock ;
@@ -122,9 +123,8 @@ public void remove() throws QuickAccessServiceException {
122
123
//validate
123
124
xmlValidator .validate (new StreamSource (new StringReader (placesContent )));
124
125
//modify
125
- var placesContentPart1 = placesContent .substring (0 , idIndex );
126
- int openingTagIndex = placesContentPart1 .lastIndexOf ("<bookmark href=" );
127
- var contentToWrite1 = placesContentPart1 .substring (0 , openingTagIndex ).stripTrailing ();
126
+ int openingTagIndex = indexOfEntryOpeningTag (placesContent , idIndex );
127
+ var contentToWrite1 = placesContent .substring (0 , openingTagIndex ).stripTrailing ();
128
128
129
129
int closingTagEndIndex = placesContent .indexOf ('>' , placesContent .indexOf ("</bookmark" , idIndex ));
130
130
var part2Tmp = placesContent .substring (closingTagEndIndex + 1 ).split ("\\ v+" , 2 ); //removing leading vertical whitespaces, but no indentation
@@ -144,6 +144,17 @@ public void remove() throws QuickAccessServiceException {
144
144
MODIFY_LOCK .unlock ();
145
145
}
146
146
}
147
+
148
+ private int indexOfEntryOpeningTag (String placesContent , int idIndex ) {
149
+ var xmlWhitespaceChars = List .of (' ' , '\t' , '\n' );
150
+ for (char c : xmlWhitespaceChars ) {
151
+ int idx = placesContent .lastIndexOf ("<bookmark" + c , idIndex );
152
+ if (idx != -1 ) {
153
+ return idx ;
154
+ }
155
+ }
156
+ throw new IllegalStateException ("File " + PLACES_FILE + " is valid xbel file, but does not contain opening bookmark tag." );
157
+ }
147
158
}
148
159
149
160
@ CheckAvailability
0 commit comments