Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2584: No longer check clipboard if ref code exists on launch. #2585

Merged
merged 27 commits into from May 27, 2020
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7101d33
Added support for pre-determined / binary related ref codes.
jhreis May 11, 2020
646e5bd
Clipboard processing added.
jhreis May 11, 2020
2359577
Merge branch 'development' into referral_fixes
jhreis May 11, 2020
624dabc
Clear clipboard after successful ref promo read.
jhreis May 11, 2020
15bfead
Cleaned up code a bit, no functional changes.
jhreis May 18, 2020
6fdb085
Added ref code validation.
jhreis May 18, 2020
8214d99
Changed ref code sanitzation to use regex.
jhreis May 18, 2020
285fe1e
Added unit tests for ref code sanitization.
jhreis May 18, 2020
aaa762e
Removed unnecessary comment.
jhreis May 18, 2020
3ce30ea
Merge branch 'development' into referral_fixes
jhreis May 18, 2020
16d5037
Added path components helper to avoid manually adding forward slashes.
jhreis May 18, 2020
576ae4a
Comment cleanup.
jhreis May 20, 2020
834a1fc
Fixed crash from bad referral situation.
jhreis May 20, 2020
98253b6
Fixed S3 bucket endpoint for enterprise builds.
jhreis May 21, 2020
ade056f
Merge branch 'development' into referral_fixes
jhreis May 21, 2020
411481f
Fix #2565: Retry ref code lookup on subsequent launches.
jhreis May 22, 2020
17f0717
Merge branch 'development' into referral_fixes
jhreis May 22, 2020
c8e6630
Merge branch 'referral_fixes' into fix-2565
jhreis May 22, 2020
6bcc4f9
Merge remote-tracking branch 'origin/development' into fix-2565
iccub May 25, 2020
9f20fc8
Merge remote-tracking branch 'origin/development' into fix-2565
iccub May 25, 2020
24744c4
Merge branch 'development' into fix-2565
jhreis May 26, 2020
aae0eb8
Fixed URP lookup flag placement.
jhreis May 26, 2020
92f0562
Add retry timer.
iccub May 27, 2020
78d2f75
Move to struct.
iccub May 27, 2020
6c8edfc
Fix #2584: No longer check clipboard if ref code exists on launch.
jhreis May 27, 2020
d55b022
Merge branch 'fix-2565' into fix-2584
jhreis May 27, 2020
350f766
Merge branch 'development' into fix-2584
jhreis May 27, 2020
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Changed ref code sanitzation to use regex.

  • Loading branch information
jhreis committed May 18, 2020
commit 8214d99dbc457f76e3ff9578b6064b383f7d7d20
@@ -194,28 +194,16 @@ public class UserReferralProgram {
/// Uses very strict matching.
/// Returns the sanitized code, or nil if no code was found
public class func sanitize(input: String?) -> String? {
guard var code = input, code.hasPrefix(self.clipboardPrefix) else { return nil }
guard var input = input, input.hasPrefix(self.clipboardPrefix) else { return nil }

// +1 to strip off `:` that proceeds the defined prefix
code.removeFirst(self.clipboardPrefix.count + 1)
input.removeFirst(self.clipboardPrefix.count + 1)
// Add any other potential validation here, e.g. validating the actual ref code string
if code.count != 6 { return nil }
let letters = code.prefix(3)
let numbers = code.suffix(3)

// Cannot use `isLetters` or `isUppercase` b/inc Æ and the like
let validLetters = letters.allSatisfy(("A"..."Z").contains)

// Cannot use `isNumber` b/inc 万 and the like
let validNumbers = numbers.allSatisfy(("0"..."9").contains)

// Both conditions must be met
return validLetters && validNumbers ? code : nil

// Regex solution
// let valid = code.range(of: #"\b[A-Z]{3}[0-9]{3}\b"#, options: .regularExpression) != nil // true
let valid = input.range(of: #"\b[A-Z]{3}[0-9]{3}\b"#, options: .regularExpression) != nil // true
// Both conditions must be met
return valid ? input : nil
}

/// Same as `customHeaders` only blocking on result, to gaurantee data is available
@@ -0,0 +1,30 @@
// Copyright 2020 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
import XCTest

class UserReferralProgramTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.