[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/master] Always use Locale.US when parsing dates.
commit d2d4293749c211a5cf68b56bb9f3e869118d2c59
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Sun Sep 13 15:43:57 2015 +0200
Always use Locale.US when parsing dates.
Spotted by iwakeh. Fixes #17033.
---
src/org/torproject/descriptor/impl/ParseHelper.java | 3 ++-
.../descriptor/impl/DescriptorCollectorImplTest.java | 14 ++++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/org/torproject/descriptor/impl/ParseHelper.java b/src/org/torproject/descriptor/impl/ParseHelper.java
index 761a93d..4e91e92 100644
--- a/src/org/torproject/descriptor/impl/ParseHelper.java
+++ b/src/org/torproject/descriptor/impl/ParseHelper.java
@@ -6,6 +6,7 @@ import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
import java.util.SortedMap;
import java.util.TimeZone;
@@ -156,7 +157,7 @@ public class ParseHelper {
static DateFormat getDateFormat(String format) {
Map<String, DateFormat> threadDateFormats = dateFormats.get();
if (!threadDateFormats.containsKey(format)) {
- DateFormat dateFormat = new SimpleDateFormat(format);
+ DateFormat dateFormat = new SimpleDateFormat(format, Locale.US);
dateFormat.setLenient(false);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
threadDateFormats.put(format, dateFormat);
diff --git a/test/org/torproject/descriptor/impl/DescriptorCollectorImplTest.java b/test/org/torproject/descriptor/impl/DescriptorCollectorImplTest.java
index 2715f12..fde8e57 100644
--- a/test/org/torproject/descriptor/impl/DescriptorCollectorImplTest.java
+++ b/test/org/torproject/descriptor/impl/DescriptorCollectorImplTest.java
@@ -116,5 +116,19 @@ public class DescriptorCollectorImplTest {
REMOTE_DIRECTORY_CONSENSUSES, directoryListing);
assertNull(remoteFiles);
}
+
+ @Test()
+ public void testInvalidLocaleDe() {
+ String directoryListing = "<tr><td valign=\"top\">"
+ + "<img src=\"/icons/unknown.gif\" alt=\"[ ]\"></td><td>"
+ + "<a href=\"2015-05-24-12-00-00-consensus\">"
+ + "2015-05-24-12-00-00-consensus</a></td>"
+ + "<td align=\"right\">24-Mai-2015 12:08 </td>"
+ + "<td align=\"right\">1.5M</td><td> </td></tr>";
+ SortedMap<String, Long> remoteFiles =
+ new DescriptorCollectorImpl().parseDirectoryListing(
+ REMOTE_DIRECTORY_CONSENSUSES, directoryListing);
+ assertNull(remoteFiles);
+ }
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits