mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-13 18:32:19 +00:00
URL encoded scrubber.
* Replace scrubber and tests. * Improves email regex performance.
This commit is contained in:
committed by
Greyson Parrelli
parent
02ea99254a
commit
37bcac40bb
@@ -1,57 +0,0 @@
|
||||
package org.thoughtcrime.securesms.logsubmit;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.thoughtcrime.securesms.logsubmit.util.Scrubber;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ScrubberTest {
|
||||
|
||||
@Test
|
||||
public void scrub_phoneNumber_solo() {
|
||||
Scrubber scrubber = new Scrubber();
|
||||
String output = scrubber.scrub("+16101234567");
|
||||
|
||||
assertEquals("+*********67", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scrub_phoneNumber_surrounded() {
|
||||
Scrubber scrubber = new Scrubber();
|
||||
String output = scrubber.scrub("Spider-Man's phone number is +16101234567 -- isn't that crazy?");
|
||||
|
||||
assertEquals("Spider-Man's phone number is +*********67 -- isn't that crazy?", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scrub_email_solo() {
|
||||
Scrubber scrubber = new Scrubber();
|
||||
String output = scrubber.scrub("jonah@dailybugle.com");
|
||||
|
||||
assertEquals("j*****************om", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scrub_email_surrounded() {
|
||||
Scrubber scrubber = new Scrubber();
|
||||
String output = scrubber.scrub("Email tips to jonah@dailybugle.com -- it's your civic duty");
|
||||
|
||||
assertEquals("Email tips to j*****************om -- it's your civic duty", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scrub_groupId_solo() {
|
||||
Scrubber scrubber = new Scrubber();
|
||||
String output = scrubber.scrub("__textsecure_group__!abcdefg1234567890");
|
||||
|
||||
assertEquals("_***********************************90", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scrub_groupId_surrounded() {
|
||||
Scrubber scrubber = new Scrubber();
|
||||
String output = scrubber.scrub("The group id is __textsecure_group__!abcdefg1234567890 and don't forget it");
|
||||
|
||||
assertEquals("The group id is _***********************************90 and don't forget it", output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package org.thoughtcrime.securesms.logsubmit.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public final class ScrubberTest {
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
return Arrays.asList(new Object[][]{
|
||||
|
||||
{ "An E164 number +15551234567",
|
||||
"An E164 number +*********67" },
|
||||
|
||||
{ "A UK number +447700900000",
|
||||
"A UK number +**********00" },
|
||||
|
||||
{ "An avatar filename: file:///data/user/0/org.thoughtcrime.securesms/files/avatars/%2B447700900099",
|
||||
"An avatar filename: file:///data/user/0/org.thoughtcrime.securesms/files/avatars/%2B**********99" },
|
||||
|
||||
{ "Multiple numbers +447700900001 +447700900002",
|
||||
"Multiple numbers +**********01 +**********02" },
|
||||
|
||||
{ "One less than shortest number +155556789",
|
||||
"One less than shortest number +155556789" },
|
||||
|
||||
{ "Shortest number +1555567890",
|
||||
"Shortest number +********90" },
|
||||
|
||||
{ "Longest number +155556789012345",
|
||||
"Longest number +*************45" },
|
||||
|
||||
{ "One more than longest number +1234567890123456",
|
||||
"One more than longest number +*************456" },
|
||||
|
||||
{ "abc@def.com",
|
||||
"a...@..." },
|
||||
|
||||
{ "An email abc@def.com",
|
||||
"An email a...@..." },
|
||||
|
||||
{ "A short email a@def.com",
|
||||
"A short email a...@..." },
|
||||
|
||||
{ "A email with multiple parts before the @ d.c+b.a@mulitpart.domain.com and a multipart domain",
|
||||
"A email with multiple parts before the @ d...@... and a multipart domain" },
|
||||
|
||||
{ "An avatar email filename: file:///data/user/0/org.thoughtcrime.securesms/files/avatars/abc@signal.org",
|
||||
"An avatar email filename: file:///data/user/0/org.thoughtcrime.securesms/files/avatars/a...@..." },
|
||||
|
||||
{ "An email and a number abc@def.com +155556789012345",
|
||||
"An email and a number a...@... +*************45" },
|
||||
|
||||
{ "__textsecure_group__!abcdefg1234567890",
|
||||
"__...group...90" },
|
||||
|
||||
{ "A group id __textsecure_group__!abcdefg0987654321 surrounded with text",
|
||||
"A group id __...group...21 surrounded with text" },
|
||||
|
||||
{ "All patterns in a row __textsecure_group__!abcdefg1234567890 +1234567890123456 abc@def.com with text after",
|
||||
"All patterns in a row __...group...90 +*************456 a...@... with text after"
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private final String input;
|
||||
private final String expected;
|
||||
|
||||
public ScrubberTest(String input, String expected) {
|
||||
this.input = input;
|
||||
this.expected = expected;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scrub() {
|
||||
assertEquals(expected, Scrubber.scrub(input).toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user