From 7c61122a1a930b72667193363ad39d45f1a7b435 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Mon, 28 Sep 2020 15:48:33 +0200 Subject: [PATCH] Hex case insensitivity & include guard for QueryParser --- src/QueryParser.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/QueryParser.h b/src/QueryParser.h index 9dd3b10..c5f67f7 100644 --- a/src/QueryParser.h +++ b/src/QueryParser.h @@ -17,6 +17,9 @@ /* This module implements URI query parsing and retrieval of value given key */ +#ifndef UWS_QUERYPARSER_H +#define UWS_QUERYPARSER_H + #include namespace uWS { @@ -65,17 +68,19 @@ namespace uWS { } /* Two bytes hex */ - char hex1 = in[i + 1] - '0'; + int hex1 = in[i + 1] - '0'; if (hex1 > 9) { + hex1 &= 223; hex1 -= 7; } - char hex2 = in[i + 2] - '0'; + int hex2 = in[i + 2] - '0'; if (hex2 > 9) { + hex2 &= 223; hex2 -= 7; } - in[out] = hex1 * 16 + hex2; + *((unsigned char *) &in[out]) = (unsigned char) (hex1 * 16 + hex2); i += 2; } else { /* Is this even a rule? */ @@ -110,4 +115,6 @@ namespace uWS { return {}; } -} \ No newline at end of file +} + +#endif \ No newline at end of file