mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-10-31 13:20:59 +00:00 
			
		
		
		
	LibWeb: Limit HTMLInputElement.size to allowed values
				
					
				
			Attempting to set `HTMLInputElement.size` to 0 via IDL now throws an IndexSizeError DOMException. Attempting to set it to a value larger than 2147483647 results in it being set to the default value.
This commit is contained in:
		
							parent
							
								
									08812a1f88
								
							
						
					
					
						commit
						ae0c87c747
					
				
				
				Notes:
				
					github-actions[bot]
				
				2024-11-29 08:50:16 +00:00 
				
			
			Author: https://github.com/tcl3
Commit: ae0c87c747
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2619
Reviewed-by: https://github.com/stelar7
			
					 4 changed files with 26 additions and 5 deletions
				
			
		|  | @ -1861,19 +1861,23 @@ WebIDL::ExceptionOr<void> HTMLInputElement::set_min_length(WebIDL::Long value) | |||
| } | ||||
| 
 | ||||
| // https://html.spec.whatwg.org/multipage/input.html#the-size-attribute
 | ||||
| unsigned HTMLInputElement::size() const | ||||
| WebIDL::UnsignedLong HTMLInputElement::size() const | ||||
| { | ||||
|     // The size attribute, if specified, must have a value that is a valid non-negative integer greater than zero.
 | ||||
|     // The size IDL attribute is limited to only positive numbers and has a default value of 20.
 | ||||
|     if (auto size_string = get_attribute(HTML::AttributeNames::size); size_string.has_value()) { | ||||
|         if (auto size = parse_non_negative_integer(*size_string); size.has_value() && size.value() != 0) | ||||
|         if (auto size = parse_non_negative_integer(*size_string); size.has_value() && *size != 0 && *size <= 2147483647) | ||||
|             return *size; | ||||
|     } | ||||
|     return 20; | ||||
| } | ||||
| 
 | ||||
| WebIDL::ExceptionOr<void> HTMLInputElement::set_size(unsigned value) | ||||
| WebIDL::ExceptionOr<void> HTMLInputElement::set_size(WebIDL::UnsignedLong value) | ||||
| { | ||||
|     if (value == 0) | ||||
|         return WebIDL::IndexSizeError::create(realm(), "Size must be greater than zero"_string); | ||||
|     if (value > 2147483647) | ||||
|         value = 20; | ||||
|     return set_attribute(HTML::AttributeNames::size, String::number(value)); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Tim Ledbetter
						Tim Ledbetter