From 77c635e033156472135f326a1cb7368496e88810 Mon Sep 17 00:00:00 2001 From: Naoki Orii Date: Wed, 16 Sep 2015 18:13:34 +0900 Subject: [PATCH] Ignore case in Record.matches This change ensures that case is ignored when determining whether a given `Record` matches against a specified user agent. For example, a `Record` representing the following example: User-agent: Mozilla Disallow: / will return `false` for `record.matches("Mozilla")`, since the current logic lowercases the user agent passed into the `matches` method, but does not lowercase the user agent for the record itself. --- src/main/java/com/trigonic/jrobotx/Record.java | 2 +- src/test/java/com/trigonic/jrobotx/RecordTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/trigonic/jrobotx/Record.java b/src/main/java/com/trigonic/jrobotx/Record.java index 9331939..2610a9f 100644 --- a/src/main/java/com/trigonic/jrobotx/Record.java +++ b/src/main/java/com/trigonic/jrobotx/Record.java @@ -49,7 +49,7 @@ public boolean matches(String userAgentString) { userAgentString = userAgentString.toLowerCase(); for (String userAgent : userAgents) { - if (userAgent.equals(ANY) || userAgentString.contains(userAgent)) { + if (userAgent.equals(ANY) || userAgentString.contains(userAgent.toLowerCase())) { result = true; break; } diff --git a/src/test/java/com/trigonic/jrobotx/RecordTest.java b/src/test/java/com/trigonic/jrobotx/RecordTest.java index 2411514..67a557b 100644 --- a/src/test/java/com/trigonic/jrobotx/RecordTest.java +++ b/src/test/java/com/trigonic/jrobotx/RecordTest.java @@ -28,7 +28,7 @@ public class RecordTest { @Test public void test() { - Set userAgents = new HashSet(Arrays.asList("netscape", "mozilla")); + Set userAgents = new HashSet(Arrays.asList("netscape", "Mozilla")); List rules = new ArrayList(); rules.add(new String[] {"Disallow", ""}); rules.add(new String[] {"Disallow", "/foo/bar/"});