Last active
June 7, 2016 21:08
-
-
Save AnthonyClink/51b1ac9a0a68ea1c0542180f8ceab013 to your computer and use it in GitHub Desktop.
fix multiple slashes in urls generated from user input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CleanUserInputUnitTests{ | |
private static final Pattern HAS_MORE_THAN_SINGLE_SLAHES_PATTERN = Pattern.compile("([^:])\\/+"); | |
@Test | |
public void regexPatternForRemovingSlashesFromBadUrlsWorksCorrectly() { | |
String input = "https://www.google.com//we////super///love/slashes//////in//generated/urls"; | |
String expectedOutput = "https://www.google.com/we/super/love/slashes/in/generated/urls"; | |
Assert.assertEquals(Pattern.compile(HAS_MORE_THAN_SINGLE_SLAHES_PATTERN).matcher(input).replaceAll("$1/"), expectedOutput); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment