mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-31 02:27:19 -04:00 
			
		
		
		
	fix rewrite bug with url query + test case
This commit is contained in:
		
							parent
							
								
									0f1e5bcebf
								
							
						
					
					
						commit
						e486c9c6e7
					
				| @ -18,8 +18,15 @@ func To(fs http.FileSystem, r *http.Request, to string, replacer httpserver.Repl | |||||||
| 
 | 
 | ||||||
| 	// try each rewrite paths | 	// try each rewrite paths | ||||||
| 	t := "" | 	t := "" | ||||||
|  | 	query := "" | ||||||
| 	for _, v := range tos { | 	for _, v := range tos { | ||||||
| 		t = path.Clean(replacer.Replace(v)) | 		t = replacer.Replace(v) | ||||||
|  | 		tparts := strings.Split(t, "?") | ||||||
|  | 		t = path.Clean(tparts[0]) | ||||||
|  | 
 | ||||||
|  | 		if len(tparts) > 1 { | ||||||
|  | 			query = tparts[1] | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
| 		// add trailing slash for directories, if present | 		// add trailing slash for directories, if present | ||||||
| 		if strings.HasSuffix(v, "/") && !strings.HasSuffix(t, "/") { | 		if strings.HasSuffix(v, "/") && !strings.HasSuffix(t, "/") { | ||||||
| @ -47,9 +54,9 @@ func To(fs http.FileSystem, r *http.Request, to string, replacer httpserver.Repl | |||||||
| 
 | 
 | ||||||
| 	// perform rewrite | 	// perform rewrite | ||||||
| 	r.URL.Path = u.Path | 	r.URL.Path = u.Path | ||||||
| 	if u.RawQuery != "" { | 	if query != "" { | ||||||
| 		// overwrite query string if present | 		// overwrite query string if present | ||||||
| 		r.URL.RawQuery = u.RawQuery | 		r.URL.RawQuery = query | ||||||
| 	} | 	} | ||||||
| 	if u.Fragment != "" { | 	if u.Fragment != "" { | ||||||
| 		// overwrite fragment if present | 		// overwrite fragment if present | ||||||
|  | |||||||
| @ -22,6 +22,7 @@ func TestTo(t *testing.T) { | |||||||
| 		{"/?a=b", "/testfile /index.php?{query}", "/testfile?a=b"}, | 		{"/?a=b", "/testfile /index.php?{query}", "/testfile?a=b"}, | ||||||
| 		{"/?a=b", "/testdir /index.php?{query}", "/index.php?a=b"}, | 		{"/?a=b", "/testdir /index.php?{query}", "/index.php?a=b"}, | ||||||
| 		{"/?a=b", "/testdir/ /index.php?{query}", "/testdir/?a=b"}, | 		{"/?a=b", "/testdir/ /index.php?{query}", "/testdir/?a=b"}, | ||||||
|  | 		{"/test?url=http://caddyserver.com", " /p/{path}?{query}", "/p/test?url=http://caddyserver.com"}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	uri := func(r *url.URL) string { | 	uri := func(r *url.URL) string { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user