mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:52:45 +00:00 
			
		
		
		
	 d8759d9656
			
		
	
	
		d8759d9656
		
	
	
	
	
		
			
			We were previously assuming that the input offsets and lengths were all in raw byte offsets into a UTF-8 string. While internally our String representation may be in UTF-8 from the external world it is seen as UTF-16, with code unit offsets passed through, and used as the returned length. Beforehand, the included test included in this commit would crash ladybird (and otherwise return wrong values). The implementation here is very inefficient, I am sure there is a much smarter way to write it so that we would not need a conversion from UTF-8 to a UTF-16 string (and then back again). Fixes: #20971
		
			
				
	
	
		
			20 lines
		
	
	
	
		
			545 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			20 lines
		
	
	
	
		
			545 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
| <script src="../include.js"></script>
 | |
| <script>
 | |
|     test(() => {
 | |
|         function dumpText(text) {
 | |
|             println(`text.data = '${text.data}', length = ${text.length}`);
 | |
|         }
 | |
| 
 | |
|         let text = new Text('🙃');
 | |
|         dumpText(text);
 | |
|         text.appendData('🙃')
 | |
|         dumpText(text);
 | |
|         text.insertData(2, 'hi🙃')
 | |
|         dumpText(text);
 | |
|         text.deleteData(2, 1)
 | |
|         dumpText(text);
 | |
|         text.replaceData(2, 5, 'replaced!')
 | |
|         dumpText(text);
 | |
|         println(text.substringData(2, 5))
 | |
|     });
 | |
| </script>
 |