Skip to content

Commit

Permalink
Fix login screen crashes when multibyte charactors are on pasteboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ngs committed May 14, 2020
1 parent 454e3e5 commit d9e4fe1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CI2Go.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@
85F409AD24686C7C00C0A76E /* totp-bitbucket.org.js in Resources */ = {isa = PBXBuildFile; fileRef = 85C6618F20E61F12007B58CD /* totp-bitbucket.org.js */; };
85F409AE24686C7C00C0A76E /* BuildTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 856609B620D965F800557249 /* BuildTableViewCell.xib */; };
85F409AF24686C7C00C0A76E /* BuildActionTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 856609BC20D96AF700557249 /* BuildActionTableViewCell.xib */; };
85F78EA9246D69E600695E77 /* ConstantsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85F78EA8246D69E600695E77 /* ConstantsTests.swift */; };
85F93BAD20DD7A0D00327DE9 /* ArtifactDownloadManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85F93BAC20DD7A0D00327DE9 /* ArtifactDownloadManager.swift */; };
85F93BB420DDCD0500327DE9 /* Interface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 85F93BB220DDCD0500327DE9 /* Interface.storyboard */; };
85F93BB620DDCD0600327DE9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 85F93BB520DDCD0600327DE9 /* Assets.xcassets */; };
Expand Down Expand Up @@ -679,6 +680,7 @@
85D9053720EAE8DB00CBF5B6 /* SettingsFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsFooterView.swift; sourceTree = "<group>"; };
85D9053C20EAF9D400CBF5B6 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
85F409BA24686C7C00C0A76E /* CI2Go.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CI2Go.app; sourceTree = BUILT_PRODUCTS_DIR; };
85F78EA8246D69E600695E77 /* ConstantsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantsTests.swift; sourceTree = "<group>"; };
85F93BAC20DD7A0D00327DE9 /* ArtifactDownloadManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArtifactDownloadManager.swift; sourceTree = "<group>"; };
85F93BB020DDCD0500327DE9 /* CI2GoWatch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CI2GoWatch.app; sourceTree = BUILT_PRODUCTS_DIR; };
85F93BB320DDCD0500327DE9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Interface.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -975,6 +977,7 @@
853D1A4E20D6389D00C7F4FC /* EndpointTests.swift */,
853D1A5A20D65E1000C7F4FC /* CompensationTests.swift */,
853D1A6C20D6C94100C7F4FC /* UserDefaultsExtensionTests.swift */,
85F78EA8246D69E600695E77 /* ConstantsTests.swift */,
);
path = CI2GoTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -1832,6 +1835,7 @@
85CAE24E20D5F15C002CD128 /* DecodingTests.swift in Sources */,
85CAE25020D5F1CE002CD128 /* TestHelper.swift in Sources */,
85CAE24020D5ED43002CD128 /* ArrayExtensionTests.swift in Sources */,
85F78EA9246D69E600695E77 /* ConstantsTests.swift in Sources */,
853D1A5B20D65E1000C7F4FC /* CompensationTests.swift in Sources */,
853D1A6D20D6C94100C7F4FC /* UserDefaultsExtensionTests.swift in Sources */,
853D1A4F20D6389D00C7F4FC /* EndpointTests.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions CI2Go/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ func isValidToken(_ token: String) -> Bool {
return tokenRegularExpression.matches(
in: token,
options: .anchored,
range: NSRange(location: 0, length: token.lengthOfBytes(using: .utf8))
range: NSRange(location: 0, length: token.count)
).count == 1 && token.count == 40
}

func isTOTP(_ token: String) -> Bool {
return totpRegularExpression.firstMatch(
in: token,
options: NSRegularExpression.MatchingOptions(rawValue: 0),
range: NSRange(location: 0, length: token.lengthOfBytes(using: .utf8))) != nil
range: NSRange(location: 0, length: token.count)) != nil
}

let shortHashLength = 7
Expand Down
29 changes: 29 additions & 0 deletions CI2GoTests/ConstantsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// ConstantsTests.swift
// CI2GoTests
//
// Created by Atsushi Nagase on 2020/05/14.
// Copyright © 2020 LittleApps Inc. All rights reserved.
//

import XCTest
@testable import CI2Go

class ConstatntsTests: XCTestCase {

func testIsTOTP() {
XCTAssertEqual(false, isTOTP(""))
XCTAssertEqual(false, isTOTP("aa"))
XCTAssertEqual(false, isTOTP("111111111"))
XCTAssertEqual(false, isTOTP("ああ"))
XCTAssertEqual(true, isTOTP("962207"))
}

func testIsValidToken() {
XCTAssertEqual(false, isValidToken(""))
XCTAssertEqual(false, isValidToken("aa"))
XCTAssertEqual(false, isValidToken("111111111"))
XCTAssertEqual(false, isValidToken("ああ"))
XCTAssertEqual(true, isValidToken("1c8e486fc496ba36cfa3c1efe4b2cb1eea95c735"))
}
}

0 comments on commit d9e4fe1

Please sign in to comment.