Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FilteredMap key matching case-insensitive #153

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bugsnag/src/main/java/com/bugsnag/util/FilteredMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private boolean shouldFilterKey(String key) {
}

for (String filter : keyFilters) {
if (key.contains(filter)) {
if (key.toLowerCase().contains(filter.toLowerCase())) {
return true;
}
}
Expand Down
8 changes: 4 additions & 4 deletions bugsnag/src/test/java/com/bugsnag/BugsnagTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ public void deliver(Serializer serializer, Object object, Map<String, String> he
(Map<String, Object>) requestTab.get("headers");

assertEquals("[FILTERED]", headersMap.get("Authorization"));
assertEquals("User:Password", headersMap.get("authorization"));
assertEquals("User:Password", headersMap.get("auth"));
assertEquals("[FILTERED]", headersMap.get("Cookie"));
assertEquals("123456ABCDEF", headersMap.get("cookie"));
assertEquals("[FILTERED]", headersMap.get("x-cookie"));
}

@Override
Expand All @@ -225,9 +225,9 @@ public void close() {
public void beforeNotify(Report report) {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "User:Password");
headers.put("authorization", "User:Password");
headers.put("auth", "User:Password");
headers.put("Cookie", "123456ABCDEF");
headers.put("cookie", "123456ABCDEF");
headers.put("x-cookie", "123456ABCDEF");

report.addToTab("request", "headers", headers);
}
Expand Down
13 changes: 8 additions & 5 deletions bugsnag/src/test/java/com/bugsnag/util/FilteredMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class FilteredMapTest {

private static final String KEY_UNFILTERED = "unfiltered";
private static final String KEY_FILTERED = "auth";
private static final String KEY_FILTERED_UPPERCASE = "myAuth";
private static final String KEY_NESTED = "nested";
private static final String KEY_UNMODIFIABLE = "unmodifiable";
private static final String VAL_UNFILTERED = "Foo";
Expand All @@ -34,6 +35,7 @@ public void setUp() {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(KEY_UNFILTERED, VAL_UNFILTERED);
map.put(KEY_FILTERED, VAL_FILTERED);
map.put(KEY_FILTERED_UPPERCASE, VAL_FILTERED);

HashMap<String, Object> nestedMap = new HashMap<String, Object>();
nestedMap.put(KEY_UNFILTERED, VAL_UNFILTERED);
Expand All @@ -47,7 +49,7 @@ public void setUp() {

@Test
public void testSize() {
assertEquals(4, filteredMap.size());
assertEquals(5, filteredMap.size());
}

@Test
Expand All @@ -60,7 +62,7 @@ public void testIsEmpty() {

@Test
public void testClear() {
assertEquals(4, filteredMap.size());
assertEquals(5, filteredMap.size());
filteredMap.clear();
assertTrue(filteredMap.isEmpty());
}
Expand Down Expand Up @@ -94,6 +96,7 @@ public void testRemove() {
@Test
public void testGet() {
assertEquals(PLACEHOLDER_FILTERED, filteredMap.get(KEY_FILTERED));
assertEquals(PLACEHOLDER_FILTERED, filteredMap.get(KEY_FILTERED_UPPERCASE));
assertEquals(VAL_UNFILTERED, filteredMap.get(KEY_UNFILTERED));

Object actual = filteredMap.get(KEY_NESTED);
Expand All @@ -108,7 +111,7 @@ public void testGet() {
@Test
public void testKeySet() {
Set<String> keySet = filteredMap.keySet();
assertEquals(4, keySet.size());
assertEquals(5, keySet.size());
assertTrue(keySet.contains(KEY_FILTERED));
assertTrue(keySet.contains(KEY_UNFILTERED));
assertTrue(keySet.contains(KEY_NESTED));
Expand All @@ -117,7 +120,7 @@ public void testKeySet() {
@Test
public void testValues() {
Collection<Object> values = filteredMap.values();
assertEquals(4, values.size());
assertEquals(5, values.size());
assertTrue(values.contains(VAL_UNFILTERED));
assertTrue(values.contains(PLACEHOLDER_FILTERED));

Expand All @@ -139,7 +142,7 @@ public void testValues() {
@Test
public void testEntrySet() {
Set<Map.Entry<String, Object>> entries = filteredMap.entrySet();
assertEquals(4, entries.size());
assertEquals(5, entries.size());

int expectedCount = 0;

Expand Down