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 #2539: Super Referrer Improvements (Clipboard) #2535
Changes from 1 commit
7101d33
646e5bd
2359577
624dabc
15bfead
6fdb085
8214d99
285fe1e
aaa762e
3ce30ea
16d5037
576ae4a
834a1fc
98253b6
ade056f
17f0717
File filter...
Jump to…
Changed ref code sanitzation to use regex.
- Loading branch information
| @@ -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) | ||
|
This conversation was marked as resolved
by jhreis
This conversation was marked as resolved
by Brandon-T
Brandon-T
Collaborator
|
||
| // Add any other potential validation here, e.g. validating the actual ref code string | ||
|
This conversation was marked as resolved
by jhreis
jumde
Collaborator
|
||
| 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 | ||
jhreis
Author
Contributor
|
||
| // 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. | ||
| } | ||
| } | ||
|
|
||
| } |
Understand this probably set in a spec somewhere, but maybe a comment about why
+ 1?