[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [onionoo/release] Remove redundant escape in regular expressions.
commit 225d504fcf7b36df7fb9f0f36c5dc07c1d4cb6ed
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon Aug 20 20:47:55 2018 +0200
Remove redundant escape in regular expressions.
Turns out that characters inside square brackets don't need to be
escaped. In fact, "^[0-9\\.]{7,15}$" does not only match valid IPv4
addresses but also strings like "1\2\3\4".
---
.../java/org/torproject/onionoo/server/ResourceServlet.java | 10 +++++-----
.../java/org/torproject/onionoo/updater/LookupService.java | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/server/ResourceServlet.java b/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
index 8f956a6..7567233 100644
--- a/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
+++ b/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
@@ -76,7 +76,7 @@ public class ResourceServlet extends HttpServlet {
+ "offset,fields").split(",")));
private static String ipv6AddressPatternString =
- "^\\[?[0-9a-fA-F:\\.]{1,39}\\]?$";
+ "^\\[?[0-9a-fA-F:.]{1,39}\\]?$";
private static Pattern ipv6AddressPattern =
Pattern.compile(ipv6AddressPatternString);
@@ -424,14 +424,14 @@ public class ResourceServlet extends HttpServlet {
}
private static Pattern searchQueryStringPattern =
- Pattern.compile("(?:.*[\\?&])*?" // lazily skip other parameters
+ Pattern.compile("(?:.*[?&])*?" // lazily skip other parameters
+ "search=([\\p{Graph} &&[^&]]+)" // capture parameter
+ "(?:&.*)*"); // skip remaining parameters
private static Pattern searchParameterPattern =
Pattern.compile("^\\$?[0-9a-fA-F]{1,40}$|" /* Hex fingerprint. */
+ "^[0-9a-zA-Z+/]{1,27}$|" /* Base64 fingerprint. */
- + "^[0-9a-zA-Z\\.]{1,19}$|" /* Nickname or IPv4 address. */
+ + "^[0-9a-zA-Z.]{1,19}$|" /* Nickname or IPv4 address. */
+ ipv6AddressPatternString + "|" /* IPv6 address. */
+ "^[a-zA-Z_]+:\"?[\\p{Graph} ]+\"?$"); /* Qualified search term. */
@@ -630,7 +630,7 @@ public class ResourceServlet extends HttpServlet {
}
private static Pattern versionParameterPattern =
- Pattern.compile("^[0-9a-zA-Z\\.-]+$");
+ Pattern.compile("^[0-9a-zA-Z.-]+$");
private String parseVersionParameter(String parameter) {
if (!versionParameterPattern.matcher(parameter).matches()) {
@@ -651,7 +651,7 @@ public class ResourceServlet extends HttpServlet {
}
private static Pattern hostNameParameterPattern =
- Pattern.compile("^[0-9A-Za-z_\\.\\-]+$");
+ Pattern.compile("^[0-9A-Za-z_.\\-]+$");
private String parseHostNameParameter(String parameter) {
if (!hostNameParameterPattern.matcher(parameter).matches()) {
diff --git a/src/main/java/org/torproject/onionoo/updater/LookupService.java b/src/main/java/org/torproject/onionoo/updater/LookupService.java
index 9c07e68..976a9ca 100644
--- a/src/main/java/org/torproject/onionoo/updater/LookupService.java
+++ b/src/main/java/org/torproject/onionoo/updater/LookupService.java
@@ -70,7 +70,7 @@ public class LookupService {
this.hasAllFiles = true;
}
- private Pattern ipv4Pattern = Pattern.compile("^[0-9\\.]{7,15}$");
+ private Pattern ipv4Pattern = Pattern.compile("^[0-9.]{7,15}$");
private long parseAddressString(String addressString) {
long addressNumber = -1L;
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits