[tor-commits] [metrics-lib/master] Always accept [SP|TAB]+ as delimiter instead of just SP.
karsten at torproject.org
karsten at torproject.org
Wed Jun 18 15:07:27 UTC 2014
commit 557c2ccfd7e09d9deef836cc993a6db92a5c2ae7
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Tue Jun 17 13:57:15 2014 +0200
Always accept [SP|TAB]+ as delimiter instead of just SP.
Better fix for #12403.
---
.../descriptor/impl/BandwidthHistoryImpl.java | 5 -----
.../descriptor/impl/BridgeNetworkStatusImpl.java | 2 +-
.../descriptor/impl/BridgePoolAssignmentImpl.java | 4 ++--
.../torproject/descriptor/impl/DirSourceEntryImpl.java | 4 ++--
.../descriptor/impl/DirectoryKeyCertificateImpl.java | 2 +-
.../descriptor/impl/ExtraInfoDescriptorImpl.java | 15 +++------------
.../torproject/descriptor/impl/MicrodescriptorImpl.java | 2 +-
.../descriptor/impl/NetworkStatusEntryImpl.java | 6 +++---
.../torproject/descriptor/impl/RelayDirectoryImpl.java | 11 ++++++-----
.../impl/RelayNetworkStatusConsensusImpl.java | 4 ++--
.../descriptor/impl/RelayNetworkStatusImpl.java | 4 ++--
.../descriptor/impl/RelayNetworkStatusVoteImpl.java | 2 +-
.../descriptor/impl/ServerDescriptorImpl.java | 15 +++------------
.../descriptor/impl/ExtraInfoDescriptorImplTest.java | 4 ++--
14 files changed, 29 insertions(+), 51 deletions(-)
diff --git a/src/org/torproject/descriptor/impl/BandwidthHistoryImpl.java b/src/org/torproject/descriptor/impl/BandwidthHistoryImpl.java
index 00953c0..1ceae54 100644
--- a/src/org/torproject/descriptor/impl/BandwidthHistoryImpl.java
+++ b/src/org/torproject/descriptor/impl/BandwidthHistoryImpl.java
@@ -13,11 +13,6 @@ public class BandwidthHistoryImpl implements BandwidthHistory {
String[] partsNoOpt) throws DescriptorParseException {
boolean isValid = false;
this.line = line;
- if (lineNoOpt.startsWith("read-history ")) {
- lineNoOpt = "read-history "
- + lineNoOpt.substring("read-history ".length());
- partsNoOpt = lineNoOpt.split(" ");
- }
if (partsNoOpt.length == 5 || partsNoOpt.length == 6) {
try {
this.historyEndMillis = ParseHelper.parseTimestampAtIndex(line,
diff --git a/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java b/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java
index 581c6e5..a63d52a 100644
--- a/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java
+++ b/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java
@@ -54,7 +54,7 @@ public class BridgeNetworkStatusImpl extends NetworkStatusImpl
Scanner s = new Scanner(new String(headerBytes)).useDelimiter("\n");
while (s.hasNext()) {
String line = s.next();
- String[] parts = line.split(" ");
+ String[] parts = line.split("[ \t]+");
String keyword = parts[0];
if (keyword.equals("published")) {
this.parsePublishedLine(line, parts);
diff --git a/src/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java b/src/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java
index 8ca4ea6..c959602 100644
--- a/src/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java
+++ b/src/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java
@@ -62,7 +62,7 @@ public class BridgePoolAssignmentImpl extends DescriptorImpl
private void parseBridgePoolAssignmentLine(String line)
throws DescriptorParseException {
- String[] parts = line.split(" ");
+ String[] parts = line.split("[ \t]+");
if (parts.length != 3) {
throw new DescriptorParseException("Illegal line '" + line
+ "' in bridge pool assignment.");
@@ -73,7 +73,7 @@ public class BridgePoolAssignmentImpl extends DescriptorImpl
private void parseBridgeLine(String line)
throws DescriptorParseException {
- String[] parts = line.split(" ");
+ String[] parts = line.split("[ \t]+");
if (parts.length < 2) {
throw new DescriptorParseException("Illegal line '" + line
+ "' in bridge pool assignment.");
diff --git a/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java b/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java
index be915f9..bd97948 100644
--- a/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java
+++ b/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java
@@ -104,7 +104,7 @@ public class DirSourceEntryImpl implements DirSourceEntry {
private void parseDirSourceLine(String line)
throws DescriptorParseException {
this.parsedExactlyOnceKeyword("dir-source");
- String[] parts = line.split(" ");
+ String[] parts = line.split("[ \t]+");
if (parts.length != 7) {
throw new DescriptorParseException("Invalid line '" + line + "'.");
}
@@ -135,7 +135,7 @@ public class DirSourceEntryImpl implements DirSourceEntry {
private void parseVoteDigestLine(String line)
throws DescriptorParseException {
this.parsedExactlyOnceKeyword("vote-digest");
- String[] parts = line.split(" ");
+ String[] parts = line.split("[ \t]+");
if (parts.length != 2) {
throw new DescriptorParseException("Invalid line '" + line + "'.");
}
diff --git a/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java b/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
index 59846df..8ef1bd7 100644
--- a/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
+++ b/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
@@ -61,7 +61,7 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl
StringBuilder crypto = null;
while (s.hasNext()) {
String line = s.next();
- String[] parts = line.split(" ");
+ String[] parts = line.split("[ \t]+");
String keyword = parts[0];
if (keyword.equals("dir-key-certificate-version")) {
this.parseDirKeyCertificateVersionLine(line, parts);
diff --git a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
index 5951da0..68cb850 100644
--- a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
@@ -93,7 +93,7 @@ public class ExtraInfoDescriptorImpl extends DescriptorImpl
String line = s.next();
String lineNoOpt = line.startsWith("opt ") ?
line.substring("opt ".length()) : line;
- String[] partsNoOpt = lineNoOpt.split(" ");
+ String[] partsNoOpt = lineNoOpt.split("[ \t]+");
String keyword = partsNoOpt[0];
if (keyword.equals("extra-info")) {
this.parseExtraInfoLine(line, lineNoOpt, partsNoOpt);
@@ -201,17 +201,8 @@ public class ExtraInfoDescriptorImpl extends DescriptorImpl
private void parseExtraInfoLine(String line, String lineNoOpt,
String[] partsNoOpt) throws DescriptorParseException {
if (partsNoOpt.length != 3) {
- /* Also accept [SP|TAB]+ where we'd previously only accept SP as
- * delimiter. This is a hotfix for #12403, because we're currently
- * not storing valid descriptors. A better place to implement this
- * would probably be in DescriptorImpl. */
- partsNoOpt = line.startsWith("opt ") ?
- line.substring("opt ".length()).split("[ \t]+") :
- line.split("[ \t]+");
- if (partsNoOpt.length != 3) {
- throw new DescriptorParseException("Illegal line '" + line
- + "' in extra-info descriptor.");
- }
+ throw new DescriptorParseException("Illegal line '" + line
+ + "' in extra-info descriptor.");
}
this.nickname = ParseHelper.parseNickname(line, partsNoOpt[1]);
this.fingerprint = ParseHelper.parseTwentyByteHexString(line,
diff --git a/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java b/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
index 30db583..c27e946 100644
--- a/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
@@ -61,7 +61,7 @@ public class MicrodescriptorImpl extends DescriptorImpl
if (line.startsWith("@")) {
continue;
}
- String[] parts = line.split(" ");
+ String[] parts = line.split("[ \t]+");
String keyword = parts[0];
if (keyword.equals("onion-key")) {
this.parseOnionKeyLine(line, parts);
diff --git a/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java b/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
index 7bfcb29..3962009 100644
--- a/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
+++ b/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
@@ -67,12 +67,12 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
throw new DescriptorParseException("Status entry must start with "
+ "an r line.");
}
- String[] rLineParts = line.split(" ");
+ String[] rLineParts = line.split("[ \t]+");
this.parseRLine(line, rLineParts);
while (s.hasNext()) {
line = s.next();
- String[] parts = !line.startsWith("opt ") ? line.split(" ") :
- line.substring("opt ".length()).split(" ");
+ String[] parts = !line.startsWith("opt ") ? line.split("[ \t]+") :
+ line.substring("opt ".length()).split("[ \t]+");
String keyword = parts[0];
if (keyword.equals("a")) {
this.parseALine(line, parts);
diff --git a/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java b/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
index 2426023..3a149a8 100644
--- a/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
@@ -192,7 +192,7 @@ public class RelayDirectoryImpl extends DescriptorImpl
}
String lineNoOpt = line.startsWith("opt ") ?
line.substring("opt ".length()) : line;
- String[] partsNoOpt = lineNoOpt.split(" ");
+ String[] partsNoOpt = lineNoOpt.split("[ \t]+");
String keyword = partsNoOpt[0];
if (keyword.equals("signed-directory")) {
this.parseSignedDirectoryLine(line, lineNoOpt, partsNoOpt);
@@ -248,14 +248,15 @@ public class RelayDirectoryImpl extends DescriptorImpl
} else {
String publishedLineNoOpt = publishedLine.startsWith("opt ") ?
publishedLine.substring("opt ".length()) : publishedLine;
- String[] publishedPartsNoOpt = publishedLineNoOpt.split(" ");
+ String[] publishedPartsNoOpt = publishedLineNoOpt.split("[ \t]+");
this.parsePublishedLine(publishedLine, publishedLineNoOpt,
publishedPartsNoOpt);
}
if (routerStatusLine != null) {
String routerStatusLineNoOpt = routerStatusLine.startsWith("opt ") ?
routerStatusLine.substring("opt ".length()) : routerStatusLine;
- String[] routerStatusPartsNoOpt = routerStatusLineNoOpt.split(" ");
+ String[] routerStatusPartsNoOpt =
+ routerStatusLineNoOpt.split("[ \t]+");
this.parseRouterStatusLine(routerStatusLine, routerStatusLineNoOpt,
routerStatusPartsNoOpt);
} else if (runningRoutersLine != null) {
@@ -264,7 +265,7 @@ public class RelayDirectoryImpl extends DescriptorImpl
runningRoutersLine.substring("opt ".length()) :
runningRoutersLine;
String[] runningRoutersPartsNoOpt =
- runningRoutersLineNoOpt.split(" ");
+ runningRoutersLineNoOpt.split("[ \t]+");
this.parseRunningRoutersLine(runningRoutersLine,
runningRoutersLineNoOpt, runningRoutersPartsNoOpt);
} else {
@@ -293,7 +294,7 @@ public class RelayDirectoryImpl extends DescriptorImpl
String line = s.next();
String lineNoOpt = line.startsWith("opt ") ?
line.substring("opt ".length()) : line;
- String[] partsNoOpt = lineNoOpt.split(" ");
+ String[] partsNoOpt = lineNoOpt.split("[ \t]+");
String keyword = partsNoOpt[0];
if (keyword.equals("directory-signature")) {
this.parseDirectorySignatureLine(line, lineNoOpt, partsNoOpt);
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
index ff963e6..faad733 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
@@ -85,7 +85,7 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
Scanner s = new Scanner(new String(headerBytes)).useDelimiter("\n");
while (s.hasNext()) {
String line = s.next();
- String[] parts = line.split(" ");
+ String[] parts = line.split("[ \t]+");
String keyword = parts[0];
if (keyword.equals("network-status-version")) {
this.parseNetworkStatusVersionLine(line, parts);
@@ -143,7 +143,7 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
Scanner s = new Scanner(new String(footerBytes)).useDelimiter("\n");
while (s.hasNext()) {
String line = s.next();
- String[] parts = line.split(" ");
+ String[] parts = line.split("[ \t]+");
String keyword = parts[0];
if (keyword.equals("directory-footer")) {
} else if (keyword.equals("bandwidth-weights")) {
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
index 6089fc7..8f0d984 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
@@ -88,7 +88,7 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
if (line.isEmpty()) {
continue;
}
- String[] parts = line.split(" ");
+ String[] parts = line.split("[ \t]+");
String keyword = parts[0];
if (keyword.equals("network-status-version")) {
this.parseNetworkStatusVersionLine(line, parts);
@@ -151,7 +151,7 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
StringBuilder crypto = null;
while (s.hasNext()) {
String line = s.next();
- String[] parts = line.split(" ");
+ String[] parts = line.split("[ \t]+");
String keyword = parts[0];
if (keyword.equals("directory-signature")) {
this.parseDirectorySignatureLine(line, parts);
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
index d0d09f7..9dbc1f0 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
@@ -76,7 +76,7 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
boolean skipCrypto = false; /* TODO Parse crypto parts. */
while (s.hasNext()) {
String line = s.next();
- String[] parts = line.split(" ");
+ String[] parts = line.split("[ \t]+");
String keyword = parts[0];
if (keyword.equals("network-status-version")) {
this.parseNetworkStatusVersionLine(line, parts);
diff --git a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
index 69ffcd8..6adc689 100644
--- a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
@@ -73,7 +73,7 @@ public class ServerDescriptorImpl extends DescriptorImpl
}
String lineNoOpt = line.startsWith("opt ") ?
line.substring("opt ".length()) : line;
- String[] partsNoOpt = lineNoOpt.split(" ");
+ String[] partsNoOpt = lineNoOpt.split("[ \t]+");
String keyword = partsNoOpt[0];
if (keyword.equals("router")) {
this.parseRouterLine(line, lineNoOpt, partsNoOpt);
@@ -170,17 +170,8 @@ public class ServerDescriptorImpl extends DescriptorImpl
private void parseRouterLine(String line, String lineNoOpt,
String[] partsNoOpt) throws DescriptorParseException {
if (partsNoOpt.length != 6) {
- /* Also accept [SP|TAB]+ where we'd previously only accept SP as
- * delimiter. This is a hotfix for #12403, because we're currently
- * not storing valid descriptors. A better place to implement this
- * would probably be in DescriptorImpl. */
- partsNoOpt = line.startsWith("opt ") ?
- line.substring("opt ".length()).split("[ \t]+") :
- line.split("[ \t]+");
- if (partsNoOpt.length != 6) {
- throw new DescriptorParseException("Illegal line '" + line
- + "' in server descriptor.");
- }
+ throw new DescriptorParseException("Illegal line '" + line
+ + "' in server descriptor.");
}
this.nickname = ParseHelper.parseNickname(line, partsNoOpt[1]);
this.address = ParseHelper.parseIpv4Address(line, partsNoOpt[2]);
diff --git a/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java b/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
index f73b4a1..12484e5 100644
--- a/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
+++ b/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
@@ -830,7 +830,7 @@ public class ExtraInfoDescriptorImplTest {
+ "-4713350144,-4723824640,-4710717440,-4572675072");
}
- @Test(expected = DescriptorParseException.class)
+ @Test()
public void testReadHistoryTabInterval()
throws DescriptorParseException {
DescriptorBuilder.createWithReadHistoryLine("read-history "
@@ -838,7 +838,7 @@ public class ExtraInfoDescriptorImplTest {
+ "4707695616,4699666432,4650004480,4489718784");
}
- @Test(expected = DescriptorParseException.class)
+ @Test()
public void testReadHistoryTabIntervalBytes()
throws DescriptorParseException {
DescriptorBuilder.createWithReadHistoryLine("read-history "
More information about the tor-commits
mailing list