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 #2539: Super Referrer Improvements (Clipboard) #2535

Merged
merged 16 commits into from May 25, 2020
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Added ref code validation.

  • Loading branch information
jhreis committed May 18, 2020
commit 6fdb085b61de86041c0bee88a712365602ebc0c6
@@ -194,13 +194,28 @@ 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 input = input, input.hasPrefix(self.clipboardPrefix) else { return nil }
guard var code = input, code.hasPrefix(self.clipboardPrefix) else { return nil }

// +1 to strip off `:` that proceeds the defined prefix
input.removeFirst(self.clipboardPrefix.count + 1)
code.removeFirst(self.clipboardPrefix.count + 1)
// Add any other potential validation here, e.g. validating the actual ref code string
This conversation was marked as resolved by jhreis

This comment has been minimized.

This comment has been minimized.

Copy link
@Brandon-T

Brandon-T May 11, 2020

Collaborator

The ref code is guaranteed to be 6 upper-case, 0-9 codes?

This comment has been minimized.

Copy link
@BrendanEich

BrendanEich May 11, 2020

Member

Refcode must be ABC123 format, 3 uppercase alphabetic and 3 decimal digits.

This comment has been minimized.

Copy link
@jhreis

jhreis May 12, 2020

Author Contributor

@jumde Please finalize this on the spec first.

This comment has been minimized.

Copy link
@jhreis

jhreis May 18, 2020

Author Contributor

Updated regex per spec.

return input.isEmpty ? nil : input
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
}

/// Same as `customHeaders` only blocking on result, to gaurantee data is available
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.