diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a9f9c6781..3ec4d288aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Ignore trailing slashes when comparing the configured URL with the auth token's embedded URL, removing a spurious conflict warning ([#3420](https://github.com/getsentry/sentry-cli/pull/3420)) + ## 3.8.0 ### Improvements diff --git a/src/config.rs b/src/config.rs index a12b6cf57b..7e96ca3b7a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -771,7 +771,7 @@ fn merge_config_source(base: &mut Ini, overlay: &Ini) -> Option) { if let Some(manually_configured_url) = manually_configured_url { - if manually_configured_url != token_url { + if !urls_equivalent(token_url, manually_configured_url) { warn!( "Using {token_url} (embedded in token) rather than manually-configured URL \ {manually_configured_url}. To use {manually_configured_url}, please provide an \ @@ -781,6 +781,12 @@ fn warn_about_conflicting_urls(token_url: &str, manually_configured_url: Option< } } +/// Returns whether two URLs refer to the same Sentry instance, ignoring +/// trailing slashes (`https://sentry.io` and `https://sentry.io/` are equal). +fn urls_equivalent(a: &str, b: &str) -> bool { + a.trim_end_matches('/') == b.trim_end_matches('/') +} + fn find_global_config_file() -> Result { let home_dir_file = dirs::home_dir().map(|p| p.join(CONFIG_RC_FILE_NAME)); let config_dir_file = dirs::config_dir().map(|p| p.join(CONFIG_INI_FILE_PATH)); @@ -1085,4 +1091,28 @@ mod tests { "https://us.sentry.io/api/0/organizations/test-org/chunk-upload/" ); } + + #[test] + fn urls_equivalent_ignores_trailing_slashes() { + assert!(urls_equivalent("https://sentry.io", "https://sentry.io/")); + assert!(urls_equivalent("https://sentry.io/", "https://sentry.io")); + assert!(urls_equivalent("https://sentry.io", "https://sentry.io")); + assert!(urls_equivalent( + "http://localhost:8000", + "http://localhost:8000/" + )); + } + + #[test] + fn urls_equivalent_detects_different_urls() { + assert!(!urls_equivalent( + "https://sentry.io", + "https://us.sentry.io" + )); + assert!(!urls_equivalent( + "https://sentry.io", + "https://sentry.io.evil.com" + )); + assert!(!urls_equivalent("https://sentry.io", "http://sentry.io/")); + } }