mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	
				
					committed by
					
						
						Lunny Xiao
					
				
			
			
				
	
			
			
			
						parent
						
							15f6ec9632
						
					
				
				
					commit
					35c3510335
				
			@@ -72,8 +72,8 @@ func URLJoin(base string, elems ...string) string {
 | 
				
			|||||||
		return ""
 | 
							return ""
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	joinedURL := baseURL.ResolveReference(argURL).String()
 | 
						joinedURL := baseURL.ResolveReference(argURL).String()
 | 
				
			||||||
	if !baseURL.IsAbs() {
 | 
						if !baseURL.IsAbs() && !strings.HasPrefix(base, "/") {
 | 
				
			||||||
		return joinedURL[1:] // Removing leading '/'
 | 
							return joinedURL[1:] // Removing leading '/' if needed
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return joinedURL
 | 
						return joinedURL
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,6 +32,12 @@ func TestURLJoin(t *testing.T) {
 | 
				
			|||||||
			"a/", "b/c/", "/../d/"),
 | 
								"a/", "b/c/", "/../d/"),
 | 
				
			||||||
		newTest("https://try.gitea.io/a/b/c#d",
 | 
							newTest("https://try.gitea.io/a/b/c#d",
 | 
				
			||||||
			"https://try.gitea.io", "a/b", "c#d"),
 | 
								"https://try.gitea.io", "a/b", "c#d"),
 | 
				
			||||||
 | 
							newTest("/a/b/d",
 | 
				
			||||||
 | 
								"/a/", "b/c/", "/../d/"),
 | 
				
			||||||
 | 
							newTest("/a/b/c",
 | 
				
			||||||
 | 
								"/a", "b/c/"),
 | 
				
			||||||
 | 
							newTest("/a/b/c#hash",
 | 
				
			||||||
 | 
								"/a", "b/c#hash"),
 | 
				
			||||||
	} {
 | 
						} {
 | 
				
			||||||
		assert.Equal(t, test.Expected, URLJoin(test.Base, test.Elements...))
 | 
							assert.Equal(t, test.Expected, URLJoin(test.Base, test.Elements...))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user