Skip to content

Instantly share code, notes, and snippets.

@themisir
Created June 2, 2021 18:42
Show Gist options
  • Save themisir/342b9230acbc6f3527fe4acdd960bab4 to your computer and use it in GitHub Desktop.
Save themisir/342b9230acbc6f3527fe4acdd960bab4 to your computer and use it in GitHub Desktop.
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