From c1e8ba9aefd699f4e6470bdb856aacb501e5897a Mon Sep 17 00:00:00 2001 From: Brian Clifton Date: Wed, 11 Apr 2018 21:51:59 -0700 Subject: [PATCH] Revert "Merge pull request #13756 from NejcZdovc/fix/#13754-regex" This reverts commit 06c774bd040430d0269b4e98578fdee5c1692e0a. --- app/cmdLine.js | 4 ++-- build/pkg-scripts/postinstall | 2 +- build/pkg-scripts/postinstall-test.sh | 17 ----------------- test/unit/app/cmdLineTest.js | 25 ------------------------- 4 files changed, 3 insertions(+), 45 deletions(-) delete mode 100644 build/pkg-scripts/postinstall-test.sh diff --git a/app/cmdLine.js b/app/cmdLine.js index 76b716c360c..ae1eee19410 100644 --- a/app/cmdLine.js +++ b/app/cmdLine.js @@ -17,6 +17,7 @@ const fs = require('fs') const path = require('path') const isDarwin = process.platform === 'darwin' +const promoCodeFilenameRegex = /-([a-zA-Z\d]{3}\d{3})\s?(?:\(\d+\))?$/g const debugTabEventsFlagName = '--debug-tab-events' let appInitialized = false @@ -165,9 +166,8 @@ const api = module.exports = { // parse promo code from installer path // first, get filename const fileName = path.win32.parse(installerPath).name - const promoCodeFilenameRegex = /-(([a-zA-Z\d]{3}\d{3})|([a-zA-Z]{1,}-[a-zA-Z]{1,}))\s?(?:\(\d+\))?$/g const matches = promoCodeFilenameRegex.exec(fileName) - if (matches && matches.length > 1) { + if (matches && matches.length === 2) { return matches[1] } return null diff --git a/build/pkg-scripts/postinstall b/build/pkg-scripts/postinstall index 2ec447e697f..5af84b1743b 100755 --- a/build/pkg-scripts/postinstall +++ b/build/pkg-scripts/postinstall @@ -8,7 +8,7 @@ installationPath=$2 # TODO: ugly to assume the name of the app, especially with multi-channel. # Luckily for now, release channel is the only channel with a pkg installer. installationAppPath="$installationPath/Brave.app" -installerPathPromoCodeRegex='.+-(([a-zA-Z0-9]{3}[0-9]{3})|([a-zA-Z]{1,}-[a-zA-Z]{1,}))([[:blank:]]?\([0-9]+\))?\.pkg$' +installerPathPromoCodeRegex='.+-([a-zA-Z0-9]{3}[0-9]{3})([[:blank:]]?\([0-9]+\))?\.pkg$' userDataDir="$HOME/Library/Application Support/brave" promoCodePath="$userDataDir/promoCode" # pkg runs this script as root so we need to get current username diff --git a/build/pkg-scripts/postinstall-test.sh b/build/pkg-scripts/postinstall-test.sh deleted file mode 100644 index 78ed29080c8..00000000000 --- a/build/pkg-scripts/postinstall-test.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -installerPath=$1 -installerPathPromoCodeRegex='.+-(([a-zA-Z0-9]{3}[0-9]{3})|([a-zA-Z]{1,}-[a-zA-Z]{1,}))([[:blank:]]?\([0-9]+\))?\.pkg$' -echo "Installer path is: $installerPath" - -if [[ $installerPath =~ $installerPathPromoCodeRegex ]]; then - echo "Installer path matched for promo code" - n=${#BASH_REMATCH[*]} - if [ $n -ge 1 ]; then - promoCode=${BASH_REMATCH[1]} - echo "Got promo code: $promoCode" - fi -else - echo "Installer path did not match for promo code" -fi - -exit 0 diff --git a/test/unit/app/cmdLineTest.js b/test/unit/app/cmdLineTest.js index 2d6ba175598..e99e3fc5c92 100644 --- a/test/unit/app/cmdLineTest.js +++ b/test/unit/app/cmdLineTest.js @@ -52,31 +52,6 @@ describe('cmdLine', function () { const result = this.cmdLine.getFirstRunPromoCode(args) assert.equal(result, promoCode) }) - - it('finds and parses promo code when we have multiple downloads', function () { - const promoCode = 'pem001 (1)' - const validPromoCodeInstallerPath = `d:\\my\\location\\on-disk\\in-a-folder-tes301\\Setup-Brave-x64-${promoCode}.exe` - const args = [...initialArgs, key, validPromoCodeInstallerPath, '--other', 'arg', '--and-another'] - const result = this.cmdLine.getFirstRunPromoCode(args) - assert.equal(result, 'pem001') - }) - - it('finds and parses promo code 2', function () { - const promoCode = 'org-name' - const validPromoCodeInstallerPath = `d:\\my\\location\\on-disk\\in-a-folder-tes301\\Setup-Brave-x64-${promoCode}.exe` - const args = [...initialArgs, key, validPromoCodeInstallerPath, '--other', 'arg', '--and-another'] - const result = this.cmdLine.getFirstRunPromoCode(args) - assert.equal(result, promoCode) - }) - - it('finds and parses promo code 2 when we have multiple downloads', function () { - const promoCode = 'org-name (1)' - const validPromoCodeInstallerPath = `d:\\my\\location\\on-disk\\in-a-folder-tes301\\Setup-Brave-x64-${promoCode}.exe` - const args = [...initialArgs, key, validPromoCodeInstallerPath, '--other', 'arg', '--and-another'] - const result = this.cmdLine.getFirstRunPromoCode(args) - assert.equal(result, 'org-name') - }) - it(`does not find promo code when there isn't one`, function () { const noPromoCodeInstallerPath = `d:\\my\\location\\on-disk\\in-a-folder-tes301\\Setup-Brave-x64.exe` const args = [...initialArgs, key, noPromoCodeInstallerPath, '--other', 'arg', '--and-another']