mirror of
				https://github.com/pragma-/pbot.git
				synced 2025-11-04 08:37:24 +01:00 
			
		
		
		
	pbot-vm: use coderef to simplify escaping of malformed Unicode
This commit is contained in:
		
							parent
							
								
									5bc47b61d9
								
							
						
					
					
						commit
						110912e85d
					
				@ -154,14 +154,7 @@ sub gdbmi_to_hash($text, $makejson = 1) {
 | 
			
		||||
    $text =~ s/\\+(\d{3})/$1 >= 0x20 ? chr oct $1 : "\\\\$1"/ge;
 | 
			
		||||
 | 
			
		||||
    # escape malformed unicode
 | 
			
		||||
    my $octets;
 | 
			
		||||
 | 
			
		||||
    while (1) {
 | 
			
		||||
        $octets .= decode('UTF-8', $text, Encode::FB_QUIET);
 | 
			
		||||
        last if not length $text;
 | 
			
		||||
        $text =~ s/(.)/sprintf '\\\\x%X', ord $1/e;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    my $octets = decode('UTF-8', $text, sub { sprintf '\\\\x%X', shift });
 | 
			
		||||
    $text = encode('UTF-8', $octets, Encode::FB_CROAK);
 | 
			
		||||
 | 
			
		||||
    # escape invalid JSON characters
 | 
			
		||||
 | 
			
		||||
@ -25,7 +25,7 @@ use PBot::Imports;
 | 
			
		||||
# These are set by the /misc/update_version script
 | 
			
		||||
use constant {
 | 
			
		||||
    BUILD_NAME     => "PBot",
 | 
			
		||||
    BUILD_REVISION => 4524,
 | 
			
		||||
    BUILD_REVISION => 4525,
 | 
			
		||||
    BUILD_DATE     => "2022-04-04",
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user