Created
June 2, 2021 18:42
-
-
Save themisir/342b9230acbc6f3527fe4acdd960bab4 to your computer and use it in GitHub Desktop.
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
bool matchesWithoutNormalization(String url, String baseUrl) { | |
return url.startsWith(baseUrl); | |
} | |
bool matchesWithNormalization(String url, String baseUrl) { | |
if (!baseUrl.endsWith('/')) baseUrl = '$baseUrl/'; | |
return url.startsWith(baseUrl); | |
} | |
void main() { | |
for (final kv in { | |
'http://pub.dev/packages/': 'http://pub.dev', | |
'http://pub.dev.attacker.com/packages': 'http://pub.dev', | |
}.entries) { | |
print('${kv.value} -> ${kv.key}'); | |
print('matchesWithoutNormalization: ${matchesWithoutNormalization(kv.key, kv.value)}'); | |
print('matchesWithNormalization: ${matchesWithNormalization(kv.key, kv.value)}'); | |
print(''); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment