Diff

util/hex.lua @ 6802:442019e955dc

util.hex: Normalize hex to lowercase and discard non-hex input
author Kim Alvefur <zash@zash.se>
date Wed, 26 Aug 2015 14:32:20 +0200
parent 6545:ec566d7cd518
child 12355:a0ff5c438e9d
line wrap: on
line diff
--- a/util/hex.lua	Wed Aug 26 13:17:10 2015 +0200
+++ b/util/hex.lua	Wed Aug 26 14:32:20 2015 +0200
@@ -1,6 +1,7 @@
 local s_char = string.char;
 local s_format = string.format;
 local s_gsub = string.gsub;
+local s_lower = string.lower;
 
 local char_to_hex = {};
 local hex_to_char = {};
@@ -19,7 +20,7 @@
 end
 
 local function from(s)
-	return (s_gsub(s, "..", hex_to_char));
+	return (s_gsub(s_lower(s), "%X*(%x%x)%X*", hex_to_char));
 end
 
 return { to = to, from = from }