mirror of
				https://github.com/labstack/echo.git
				synced 2025-10-30 23:57:38 +02:00 
			
		
		
		
	case sensitive matching prioritized
This commit is contained in:
		
				
					committed by
					
						 Vishal Rana
						Vishal Rana
					
				
			
			
				
	
			
			
			
						parent
						
							01cfe83efe
						
					
				
				
					commit
					6007218835
				
			
							
								
								
									
										25
									
								
								bind.go
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								bind.go
									
									
									
									
									
								
							| @@ -104,18 +104,19 @@ func (b *DefaultBinder) bindData(ptr interface{}, data map[string][]string, tag | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		var inputValue []string | 		inputValue, exists := data[inputFieldName] | ||||||
| 		var exists bool | 		if !exists { | ||||||
|  | 			// Go json.Unmarshal supports case insensitive binding.  However the | ||||||
| 		// Go json.Unmarshal supports case insensitive binding.  However the url | 			// url params are bound case sensitive which is inconsistent.  To | ||||||
| 		// params are bound case sensitive which is inconsistent.  To fix this | 			// fix this we must check all of the map values in a | ||||||
| 		// we must check all of the map values in a case-insensitive search. | 			// case-insensitive search. | ||||||
| 		inputFieldName = strings.ToLower(inputFieldName) | 			inputFieldName = strings.ToLower(inputFieldName) | ||||||
| 		for k, v := range data { | 			for k, v := range data { | ||||||
| 			if strings.ToLower(k) == inputFieldName { | 				if strings.ToLower(k) == inputFieldName { | ||||||
| 				inputValue = v | 					inputValue = v | ||||||
| 				exists = true | 					exists = true | ||||||
| 				break | 					break | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										13
									
								
								bind_test.go
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								bind_test.go
									
									
									
									
									
								
							| @@ -165,6 +165,19 @@ func TestBindQueryParamsCaseInsensitive(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func TestBindQueryParamsCaseSensitivePrioritized(t *testing.T) { | ||||||
|  | 	e := New() | ||||||
|  | 	req := httptest.NewRequest(GET, "/?id=1&ID=2&NAME=Jon+Snow&name=Jon+Doe", nil) | ||||||
|  | 	rec := httptest.NewRecorder() | ||||||
|  | 	c := e.NewContext(req, rec) | ||||||
|  | 	u := new(user) | ||||||
|  | 	err := c.Bind(u) | ||||||
|  | 	if assert.NoError(t, err) { | ||||||
|  | 		assert.Equal(t, 1, u.ID) | ||||||
|  | 		assert.Equal(t, "Jon Doe", u.Name) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
| func TestBindUnmarshalParam(t *testing.T) { | func TestBindUnmarshalParam(t *testing.T) { | ||||||
| 	e := New() | 	e := New() | ||||||
| 	req := httptest.NewRequest(GET, "/?ts=2016-12-06T19:09:05Z&sa=one,two,three&ta=2016-12-06T19:09:05Z&ta=2016-12-06T19:09:05Z&ST=baz", nil) | 	req := httptest.NewRequest(GET, "/?ts=2016-12-06T19:09:05Z&sa=one,two,three&ta=2016-12-06T19:09:05Z&ta=2016-12-06T19:09:05Z&ST=baz", nil) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user