Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit 06c774b

Browse files
committed
Merge pull request #13756 from NejcZdovc/fix/#13754-regex
Adds s-s to the referral code
1 parent ca59178 commit 06c774b

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

app/cmdLine.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const fs = require('fs')
1717
const path = require('path')
1818

1919
const isDarwin = process.platform === 'darwin'
20-
const promoCodeFilenameRegex = /-([a-zA-Z\d]{3}\d{3})\s?(?:\(\d+\))?$/g
2120
const debugTabEventsFlagName = '--debug-tab-events'
2221

2322
let appInitialized = false
@@ -166,8 +165,9 @@ const api = module.exports = {
166165
// parse promo code from installer path
167166
// first, get filename
168167
const fileName = path.win32.parse(installerPath).name
168+
const promoCodeFilenameRegex = /-(([a-zA-Z\d]{3}\d{3})|([a-zA-Z]{1,}-[a-zA-Z]{1,}))\s?(?:\(\d+\))?$/g
169169
const matches = promoCodeFilenameRegex.exec(fileName)
170-
if (matches && matches.length === 2) {
170+
if (matches && matches.length > 1) {
171171
return matches[1]
172172
}
173173
return null

build/pkg-scripts/postinstall

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ installationPath=$2
88
# TODO: ugly to assume the name of the app, especially with multi-channel.
99
# Luckily for now, release channel is the only channel with a pkg installer.
1010
installationAppPath="$installationPath/Brave.app"
11-
installerPathPromoCodeRegex='.+-([a-zA-Z0-9]{3}[0-9]{3})([[:blank:]]?\([0-9]+\))?\.pkg$'
11+
installerPathPromoCodeRegex='.+-(([a-zA-Z0-9]{3}[0-9]{3})|([a-zA-Z]{1,}-[a-zA-Z]{1,}))([[:blank:]]?\([0-9]+\))?\.pkg$'
1212
userDataDir="$HOME/Library/Application Support/brave"
1313
promoCodePath="$userDataDir/promoCode"
1414
# pkg runs this script as root so we need to get current username

build/pkg-scripts/postinstall-test.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
installerPath=$1
3+
installerPathPromoCodeRegex='.+-(([a-zA-Z0-9]{3}[0-9]{3})|([a-zA-Z]{1,}-[a-zA-Z]{1,}))([[:blank:]]?\([0-9]+\))?\.pkg$'
4+
echo "Installer path is: $installerPath"
5+
6+
if [[ $installerPath =~ $installerPathPromoCodeRegex ]]; then
7+
echo "Installer path matched for promo code"
8+
n=${#BASH_REMATCH[*]}
9+
if [ $n -ge 1 ]; then
10+
promoCode=${BASH_REMATCH[1]}
11+
echo "Got promo code: $promoCode"
12+
fi
13+
else
14+
echo "Installer path did not match for promo code"
15+
fi
16+
17+
exit 0

test/unit/app/cmdLineTest.js

+25
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,31 @@ describe('cmdLine', function () {
5252
const result = this.cmdLine.getFirstRunPromoCode(args)
5353
assert.equal(result, promoCode)
5454
})
55+
56+
it('finds and parses promo code when we have multiple downloads', function () {
57+
const promoCode = 'pem001 (1)'
58+
const validPromoCodeInstallerPath = `d:\\my\\location\\on-disk\\in-a-folder-tes301\\Setup-Brave-x64-${promoCode}.exe`
59+
const args = [...initialArgs, key, validPromoCodeInstallerPath, '--other', 'arg', '--and-another']
60+
const result = this.cmdLine.getFirstRunPromoCode(args)
61+
assert.equal(result, 'pem001')
62+
})
63+
64+
it('finds and parses promo code 2', function () {
65+
const promoCode = 'org-name'
66+
const validPromoCodeInstallerPath = `d:\\my\\location\\on-disk\\in-a-folder-tes301\\Setup-Brave-x64-${promoCode}.exe`
67+
const args = [...initialArgs, key, validPromoCodeInstallerPath, '--other', 'arg', '--and-another']
68+
const result = this.cmdLine.getFirstRunPromoCode(args)
69+
assert.equal(result, promoCode)
70+
})
71+
72+
it('finds and parses promo code 2 when we have multiple downloads', function () {
73+
const promoCode = 'org-name (1)'
74+
const validPromoCodeInstallerPath = `d:\\my\\location\\on-disk\\in-a-folder-tes301\\Setup-Brave-x64-${promoCode}.exe`
75+
const args = [...initialArgs, key, validPromoCodeInstallerPath, '--other', 'arg', '--and-another']
76+
const result = this.cmdLine.getFirstRunPromoCode(args)
77+
assert.equal(result, 'org-name')
78+
})
79+
5580
it(`does not find promo code when there isn't one`, function () {
5681
const noPromoCodeInstallerPath = `d:\\my\\location\\on-disk\\in-a-folder-tes301\\Setup-Brave-x64.exe`
5782
const args = [...initialArgs, key, noPromoCodeInstallerPath, '--other', 'arg', '--and-another']

0 commit comments

Comments
 (0)