diff options
| author | Stephen Blott | 2014-11-02 06:00:41 +0000 |
|---|---|---|
| committer | Stephen Blott | 2014-11-02 06:00:41 +0000 |
| commit | 406f0e0e23266fbc483fc17602cd5dbe4a581168 (patch) | |
| tree | 6800ae1e3d45bacd6a71f2ab8a9622e94a78ac4c | |
| parent | 8afdaabd2e66a3092bc2b122443956327e0ba679 (diff) | |
| parent | a61d69ea40c9f2683107416eccab8046ab00c87d (diff) | |
| download | vimium-406f0e0e23266fbc483fc17602cd5dbe4a581168.tar.bz2 | |
Merge Utils.hasChromePrefix from mrmr1993.
| -rw-r--r-- | lib/utils.coffee | 12 | ||||
| -rw-r--r-- | tests/unit_tests/utils_test.coffee | 14 |
2 files changed, 21 insertions, 5 deletions
diff --git a/lib/utils.coffee b/lib/utils.coffee index a93831d7..bbcee1a0 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -25,11 +25,13 @@ Utils = id = 0 -> id += 1 - hasChromePrefix: (url) -> - chromePrefixes = [ "about", "view-source", "chrome-extension", "data" ] - for prefix in chromePrefixes - return true if url.startsWith prefix - false + hasChromePrefix: do -> + chromePrefixes = [ "about:", "view-source:", "chrome-extension:", "data:" ] + (url) -> + if 0 < url.indexOf ":" + for prefix in chromePrefixes + return true if url.startsWith prefix + false # Completes a partial URL (without scheme) createFullUrl: (partialUrl) -> diff --git a/tests/unit_tests/utils_test.coffee b/tests/unit_tests/utils_test.coffee index 76a023ed..b2d656ab 100644 --- a/tests/unit_tests/utils_test.coffee +++ b/tests/unit_tests/utils_test.coffee @@ -47,6 +47,20 @@ context "convertToUrl", assert.equal "http://www.google.com/search?q=google", Utils.convertToUrl("google") assert.equal "http://www.google.com/search?q=go%20ogle.com", Utils.convertToUrl("go ogle.com") +context "hasChromePrefix", + should "detect chrome prefixes of URLs", -> + assert.isTrue Utils.hasChromePrefix "about:foobar" + assert.isTrue Utils.hasChromePrefix "view-source:foobar" + assert.isTrue Utils.hasChromePrefix "chrome-extension:foobar" + assert.isTrue Utils.hasChromePrefix "data:foobar" + assert.isTrue Utils.hasChromePrefix "data:" + assert.isFalse Utils.hasChromePrefix "" + assert.isFalse Utils.hasChromePrefix "about" + assert.isFalse Utils.hasChromePrefix "view-source" + assert.isFalse Utils.hasChromePrefix "chrome-extension" + assert.isFalse Utils.hasChromePrefix "data" + assert.isFalse Utils.hasChromePrefix "data :foobar" + context "Function currying", should "Curry correctly", -> foo = (a, b) -> "#{a},#{b}" |
