From 56373b59bc5285f9f03a5d75954146c2110a5abe Mon Sep 17 00:00:00 2001
From: fooker <fooker@lab.sh>
Date: Tue, 29 May 2018 11:53:29 +0200
Subject: [PATCH] Escape regex in device name the right way

---
 app.js     | 9 +--------
 devices.js | 2 +-
 2 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/app.js b/app.js
index e6c4e71..300e6a9 100644
--- a/app.js
+++ b/app.js
@@ -1048,20 +1048,13 @@ var firmwarewizard = function() {
     });
 
     // prepare the matches for use in regex (join by pipe and escape dots)
-    var matchString = matches.join('|').replace(/\./g, '\.');
+    var matchString = matches.map(x => x.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
 
     // match image files. The match either ends with
     // - a dash or dot (if a file extension will follow)
     // - the end of the expression (if the file extension is part of the regex)
     var reMatch = new RegExp('('+matchString+')([.-]|$)');
 
-    // check if image regexes contain regular expressions themself
-    var reCheckRegex = new RegExp(/[^\\]+[+?*]/);
-
-    if (reCheckRegex.exec(matches.join('|')) !== null) {
-      console.log("Warning! Some regular expressions for firmware images, contain unescaped characters.");
-    }
-
     var sitesLoadedSuccessfully = 0;
     for (var indexPath in config.directories) {
       // retrieve the contents of the directory
diff --git a/devices.js b/devices.js
index f953921..2b38d78 100644
--- a/devices.js
+++ b/devices.js
@@ -131,7 +131,7 @@ var devices_recommended = {
     "UniFi AP AC Pro": "ubiquiti-unifi-ac-pro",
     "UniFi AP AC Lite": "ubiquiti-unifi-ac-lite",
     "UniFi AP Outdoor": {"ubiquiti-unifi-outdoor": "", "ubiquiti-unifiap-outdoor": ""},
-    "UniFi AP Outdoor+": {"ubiquiti-unifi-outdoor-plus": "", "ubiquiti-unifiap-outdoor\\\+": "", "ubiquiti-unifiap-outdoor%2B": "", "ubiquiti-unifiap-outdoor%2b": ""}
+    "UniFi AP Outdoor+": {"ubiquiti-unifi-outdoor-plus": "", "ubiquiti-unifiap-outdoor+": "", "ubiquiti-unifiap-outdoor%2B": "", "ubiquiti-unifiap-outdoor%2b": ""}
   },
 
   "VoCore": {
-- 
GitLab