commit cdd86d2119ed4548c5785134c6c461d0eca94e79
Author: Arlo Breault <[email protected]>
Date:   Tue May 6 09:37:32 2014 -0700

    Use a regexp to test user agent strings
    
     * Suggested in
       https://trac.torproject.org/projects/tor/ticket/9041#comment:9
---
 utils.go |   15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/utils.go b/utils.go
index 8e05a07..e6fb9bb 100644
--- a/utils.go
+++ b/utils.go
@@ -13,15 +13,13 @@ import (
        "net/url"
        "os"
        "path"
+       "regexp"
        "strconv"
        "strings"
 )
 
 func IsParamSet(r *http.Request, param string) bool {
-       if len(r.URL.Query().Get(param)) > 0 {
-               return true
-       }
-       return false
+       return len(r.URL.Query().Get(param)) > 0
 }
 
 func Lang(r *http.Request) string {
@@ -57,15 +55,10 @@ func GetHost(r *http.Request) (host string, err error) {
        return
 }
 
-var TBBUserAgents = map[string]bool{
-       "Mozilla/5.0 (Windows NT 6.1; rv:10.0) Gecko/20100101 Firefox/10.0": 
true,
-       "Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0": 
true,
-       "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0": 
true,
-}
+var TBBUserAgents = regexp.MustCompile(`^Mozilla/5\.0 \(Windows NT 6\.1; 
rv:[\d]+\.0\) Gecko/20100101 Firefox/[\d]+\.0$`)
 
 func LikelyTBB(ua string) bool {
-       _, ok := TBBUserAgents[ua]
-       return ok
+       return TBBUserAgents.MatchString(ua)
 }
 
 var HaveManual = map[string]bool{

_______________________________________________
tor-commits mailing list
[email protected]
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to