# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1440592340 -7200
# Node ID 442019e955dc8e69371a81c53b888cc422a63ebd
# Parent  8b4c8e9572110b514a5a74758ad1568ea960ba95
util.hex: Normalize hex to lowercase and discard non-hex input

diff -r 8b4c8e957211 -r 442019e955dc util/hex.lua
--- 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 }