зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1265708 - Pre: Implement StringUtils.stripRef r=sebastian
MozReview-Commit-ID: AO25iiUMXLE --HG-- extra : rebase_source : 92282861ec7ab119cf104fd5aa7d904008cc5d75 extra : source : 974090a524da56fad3b8045b19461e9ae6817529
This commit is contained in:
Родитель
1468a97d80
Коммит
ef186c7689
|
@ -62,6 +62,26 @@ public class StringUtils {
|
|||
return wasSearchQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip the ref from a URL, if present
|
||||
*
|
||||
* @return The base URL, without the ref. The original String is returned if it has no ref,
|
||||
* of if the input is malformed.
|
||||
*/
|
||||
public static String stripRef(final String inputURL) {
|
||||
if (inputURL == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int refIndex = inputURL.indexOf('#');
|
||||
|
||||
if (refIndex >= 0) {
|
||||
return inputURL.substring(0, refIndex);
|
||||
}
|
||||
|
||||
return inputURL;
|
||||
}
|
||||
|
||||
public static class UrlFlags {
|
||||
public static final int NONE = 0;
|
||||
public static final int STRIP_HTTPS = 1;
|
||||
|
|
|
@ -11,6 +11,8 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.mozilla.gecko.background.testhelpers.TestRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(TestRunner.class)
|
||||
public class TestStringUtils {
|
||||
@Test
|
||||
|
@ -40,4 +42,15 @@ public class TestStringUtils {
|
|||
Assert.assertFalse(StringUtils.isHttpOrHttps("google.com"));
|
||||
Assert.assertFalse(StringUtils.isHttpOrHttps("git@github.com:mozilla/gecko-dev.git"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStripRef() {
|
||||
assertEquals(StringUtils.stripRef(null), null);
|
||||
assertEquals(StringUtils.stripRef(""), "");
|
||||
|
||||
assertEquals(StringUtils.stripRef("??AAABBBCCC"), "??AAABBBCCC");
|
||||
assertEquals(StringUtils.stripRef("https://mozilla.org"), "https://mozilla.org");
|
||||
assertEquals(StringUtils.stripRef("https://mozilla.org#BBBB"), "https://mozilla.org");
|
||||
assertEquals(StringUtils.stripRef("https://mozilla.org/#BBBB"), "https://mozilla.org/");
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче