Skip to content

Commit 8dfc60f

Browse files
committed
extended validity test for dirty.db
1 parent 3bd3539 commit 8dfc60f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/ai/susi/tools/EtherpadClient.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,22 @@ public void dirtyDBHealthCheck() {
7171
try {
7272
List<String> s = Files.readAllLines(this.dirtyDB.toPath());
7373
String l;
74-
if (s.size() == 0 || (l = s.get(s.size() - 1)).length() == 0 || l.charAt(0) == '{') return;
74+
if (s.size() == 0 || (l = s.get(s.size() - 1)).length() == 0 || dirtyDBLineOK(l)) return;
7575
// start healing
76-
while (s.size() > 0 && (l = s.get(s.size() - 1)).length() > 0 && l.charAt(0) != '{') s.remove(s.size() - 1);
76+
while (s.size() > 0 && (l = s.get(s.size() - 1)).length() > 0 && !dirtyDBLineOK(l)) s.remove(s.size() - 1);
7777
Files.write(this.dirtyDB.toPath(), s);
7878
} catch (IOException e) {
7979
e.printStackTrace();
8080
}
8181
}
82+
83+
private boolean dirtyDBLineOK(String line) {
84+
assert line != null && line.length() > 0;
85+
if (line.charAt(0) != '{') return false;
86+
if (line.charAt(line.length() - 1) != '}') return false;
87+
// we could do a json parsing here to further prove that the line is ok, but maybe that is not necessary
88+
return true;
89+
}
8290

8391
/**
8492
* check if this etherpad is private. A etherpad is private if it is running at localhost

0 commit comments

Comments
 (0)