Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
Better scrubbing of file names to allow non-Latin alphabets.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehearn committed Jan 14, 2015
1 parent 057e45c commit cfa5b54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion common/src/main/java/lighthouse/protocol/LHUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static boolean pledgeAppearsInClaim(Project forProject, LHProtos.Pledge p
}

public static String titleToUrlString(String s) {
return s.replaceAll("[^a-zA-Z0-9 ]", "").replaceAll(" ", "-").toLowerCase();
return s.replaceAll("[!@#$%^&*()_+\\\\';:?=/.,\\[\\] \\n]", "-").replaceAll("-+", "-").replaceAll("(^-+|-+$)", "").toLowerCase();
}

public static boolean isUnix() {
Expand Down
13 changes: 8 additions & 5 deletions common/src/test/java/lighthouse/protocol/ProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,6 @@ public void completeContract() throws Exception {
assertEquals(2, contract.getInputs().size());
}

@Test
public void urlScrubber() throws Exception {
assertEquals("a-really-cool-20-title-with-lots-asdf-of-weird--chars", LHUtils.titleToUrlString("A really $cool %20 Title with ;;lots asdf\n of weird // chars"));
}

@Test
public void authKeys() throws Exception {
details = Project.makeDetails(
Expand All @@ -301,4 +296,12 @@ public void authKeys() throws Exception {
// Expected.
}
}

@Test
public void titleToPath() {
assertEquals("bbc-14-01-2015-eu-lawyer-approves-ecb-bond-buying-programme", titleToUrlString("BBC 14/01/2015 EU lawyer approves ECB bond-buying programme"));
assertEquals("bob-http-example-com-1378-foo-bar", titleToUrlString("Bob http://example.com:1378/?foo=bar"));
assertEquals("a-really-cool-20-title-with-lots-asdf-of-weird-chars", titleToUrlString("A really $cool %20 Title with ;;lots asdf\n of weird // chars"));
assertEquals("български-език", titleToUrlString("български език"));
}
}

0 comments on commit cfa5b54

Please sign in to comment.