Merge branch 'v2.1-dev' as v2.1.2
[squeep-api-dingus] / lib / dingus.js
index dfddaff577312857bdc695820ed768ab680d11bd..c53e469808b26e2049d3dcd2428dbd66f50272c9 100644 (file)
@@ -1,4 +1,3 @@
-/* eslint-disable security/detect-object-injection */
 'use strict';
 
 /**
@@ -39,7 +38,10 @@ const defaultOptions = {
   querystring,
 };
 
-const cookieSplitRE = /; */;
+const cookieSplitRE = /\s*;\s*/;
+const headerParseRE = /^(?<name>[^:]+): +(?<value>.*)$/;
+const lineBreakRE = /\r\n|\n|\r/;
+const proxySplitRE = /\s*,\s*/u;
 
 class Dingus {
   /**
@@ -162,7 +164,7 @@ class Dingus {
       (this.trustProxy && req?.getHeader(Enum.Header.XRealIP)) ||
       (req?.connection?.remoteAddress) ||
       '';
-    return address.split(/\s*,\s*/u)[0];
+    return address.split(proxySplitRE)[0];
   }
 
 
@@ -175,7 +177,7 @@ class Dingus {
     // TODO: RFC7239 Forwarded support
     const protocol = (this.trustProxy && req?.getHeader(Enum.Header.XForwardedProto)) ||
       ((req?.connection?.encrypted) ? 'https' : 'http');
-    return protocol.split(/\s*,\s*/u)[0];
+    return protocol.split(proxySplitRE)[0];
   }
 
 
@@ -203,7 +205,7 @@ class Dingus {
       const [ name, value ] = common.splitFirst(cookie, '=', null).map((x) => {
         try {
           return decodeURIComponent(x.trim());
-        } catch (e) {
+        } catch (e) { // eslint-disable-line no-unused-vars
           return x;
         }
       });
@@ -583,11 +585,9 @@ class Dingus {
       return added;
     }
 
-    const lineBreakRE = /\r\n|\n|\r/;
     const lines = data.toString().split(lineBreakRE);
     common.unfoldHeaderLines(lines);
 
-    const headerParseRE = /^(?<name>[^:]+): +(?<value>.*)$/;
     lines.forEach((line) => {
       if (line) {
         const result = headerParseRE.exec(line);
@@ -651,7 +651,7 @@ class Dingus {
       if (encoding === Enum.EncodingType.Identity) {
         break;
       }
-      const suffix = Enum.EncodingTypeSuffix[encoding];
+      const suffix = Enum.EncodingTypeSuffix[encoding]; // eslint-disable-line security/detect-object-injection
       if (!suffix) {
         this.logger.error(_scope, 'supported encoding missing mapped suffix', { ctx, encoding });
         continue;