CB-14198: (all) Fix bug when running simulate --target= under non-US Windows 10 (#14)
* CB-14198: (all) Fix bug when running simulate --target= under non-US Windows 10
- change regex to parse stdout from reg.exe for browser recognition to be language independent
- Add tests for regItemPattern check, enhanced regexp pattern to avoid regression in the future
- Add "var" keyword to the "result" variable declaration
- Add test for non-latin registry key (Russian)
diff --git a/spec/browser.spec.js b/spec/browser.spec.js
index 14bcc72..ccd0307 100644
--- a/spec/browser.spec.js
+++ b/spec/browser.spec.js
@@ -18,6 +18,7 @@
var rewire = require('rewire');
var browser = rewire("../src/browser");
+var regItemPattern = browser.__get__("regItemPattern");
function expectPromise(obj){
// 3 slightly different ways of verifying a promise
@@ -75,4 +76,22 @@
done(err);
});
});
+
+ it('should recognize browser from registry with key "Default" on English Windows 10', function(done) {
+ var result = regItemPattern.exec("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.EXE (Default) REG_SZ C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
+ expect(result[2]).toBe("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe")
+ done();
+ });
+
+ it('should recognize browser from registry with key "Standard" on non-English Windows 10', function(done) {
+ var result = regItemPattern.exec("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.EXE (Standard) REG_SZ C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
+ expect(result[2]).toBe("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe")
+ done();
+ });
+
+ it('should recognize browser with non-Latin registry key on Russian Windows 10', function(done) {
+ var result = regItemPattern.exec("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.EXE (�� 㬮�砭��) REG_SZ C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
+ expect(result[2]).toBe("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe")
+ done();
+ });
});
diff --git a/src/browser.js b/src/browser.js
index 289ac68..6d13f3a 100644
--- a/src/browser.js
+++ b/src/browser.js
@@ -199,7 +199,7 @@
return prom;
}
-var regItemPattern = /\s*\(Default\)\s+(REG_SZ)\s+([^\s].*)\s*/;
+var regItemPattern = /\s*\([^)]+\)\s+(REG_SZ)\s+([^\s].*)\s*/;
function browserInstalled (browser) {
// On Windows, the 'start' command searches the path then 'App Paths' in the registry.
// We do the same here. Note that the start command uses the PATHEXT environment variable