@@ -20,7 +20,13 @@ pub fn extract_domain_from_url(url: &str) -> Option<String> {
2020}
2121
2222pub fn construct_root_url ( domain : & str ) -> String {
23- format ! ( "https://{domain}" )
23+ let url_string = format ! ( "https://{domain}" ) ;
24+ // Normalize the URL the same way CLI does to ensure consistency
25+ if let Ok ( parsed) = url:: Url :: parse ( & url_string) {
26+ parsed. to_string ( )
27+ } else {
28+ url_string
29+ }
2430}
2531
2632pub fn is_root_url ( url : & str ) -> bool {
@@ -66,13 +72,28 @@ mod tests {
6672
6773 #[ test]
6874 fn test_construct_root_url ( ) {
69- assert_eq ! ( construct_root_url( "example.com" ) , "https://example.com" ) ;
75+ assert_eq ! ( construct_root_url( "example.com" ) , "https://example.com/ " ) ;
7076 assert_eq ! (
7177 construct_root_url( "subdomain.example.com" ) ,
72- "https://subdomain.example.com"
78+ "https://subdomain.example.com/ "
7379 ) ;
7480 }
7581
82+ #[ test]
83+ fn test_construct_root_url_matches_cli_normalization ( ) {
84+ // Test that construct_root_url produces URLs that match CLI normalization
85+ // This prevents duplicate loading when user provides URLs with trailing slashes
86+ let domain = "news.ycombinator.com" ;
87+ let constructed_root = construct_root_url ( domain) ;
88+
89+ // Simulate what CLI normalization does for user input with trailing slash
90+ let user_input = "https://news.ycombinator.com/" ;
91+ let cli_normalized = url:: Url :: parse ( user_input) . unwrap ( ) . to_string ( ) ;
92+
93+ assert_eq ! ( constructed_root, cli_normalized) ;
94+ assert_eq ! ( constructed_root, "https://news.ycombinator.com/" ) ;
95+ }
96+
7697 #[ test]
7798 fn test_is_root_url ( ) {
7899 assert ! ( is_root_url( "https://example.com" ) ) ;
0 commit comments