Created
August 22, 2014 20:12
-
-
Save bdkosher/994c6b26f4b8d78ffcd1 to your computer and use it in GitHub Desktop.
Crude Groovy closure that can take a URI and strip off the query string and fragment, returning just the path part
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
def extractPathOnly = { path -> | |
switch (path) { | |
case '/': | |
path = 'index.html' | |
break | |
case { it.contains('?') }: | |
path = path.split('\\?')[0] | |
break | |
case { it.contains('#') }: | |
path = path.split('#')[0] | |
} | |
path | |
} | |
assert extractPathOnly('window.html?foo=bar') == 'window.html' | |
assert extractPathOnly('window.html?foo=bar#hash') == 'window.html' | |
assert extractPathOnly('window.html?#hash') == 'window.html' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment