diff --git a/KeePassKit b/KeePassKit index 7a4de622..1ec6abf2 160000 --- a/KeePassKit +++ b/KeePassKit @@ -1 +1 @@ -Subproject commit 7a4de6220e0ce98a458391610a6835043f4785f6 +Subproject commit 1ec6abf2fa63959045f3eab2b49bac1d57cd3b68 diff --git a/MacPass/MPAutotypeCommand.m b/MacPass/MPAutotypeCommand.m index 9f5cca46..6fe99e97 100644 --- a/MacPass/MPAutotypeCommand.m +++ b/MacPass/MPAutotypeCommand.m @@ -8,6 +8,8 @@ #import "MPAutotypeCommand.h" +#import "MPAutotypePaste.h" + #import "MPAutotypeContext.h" #import "MPKeyMapper.h" @@ -21,19 +23,47 @@ if([context isValid]) { return nil; } + NSMutableArray *commands = [[NSMutableArray alloc] initWithCapacity:10]; BOOL outsideCommand = YES; - NSInteger currentIndex; + NSString *unparsedCommand = context.normalizedCommand; while(YES) { + /* Outside Command */ if(outsideCommand) { - NSRange openingBracketRange = [context.normalizedCommand rangeOfString:@"{"]; + NSRange openingBracketRange = [unparsedCommand rangeOfString:@"{"]; if(openingBracketRange.location != NSNotFound && openingBracketRange.length == 1) { + outsideCommand = NO; + NSString *skipped = [unparsedCommand substringToIndex:openingBracketRange.location]; + unparsedCommand = [unparsedCommand substringFromIndex:openingBracketRange.location + 1]; + } + else { + /* No more opeing brackets, stop - or none at all */ + [self appendPasteCommandForContent:unparsedCommand toCommands:commands]; + break; } } + /* Inside Command */ else { + NSRange closingBracketRange = [unparsedCommand rangeOfString:@"}"]; + if(closingBracketRange.location == NSNotFound || closingBracketRange.length != 1) { + return nil; + } + outsideCommand = NO; } - } - return nil; + return commands; +} + ++ (MPAutotypeCommand *)appendPasteCommandForContent:(NSString *)pasteContent toCommands:(NSMutableArray *)commands { + if(pasteContent) { + MPAutotypePaste *pasteCommand = [[MPAutotypePaste alloc] initWithString:pasteContent]; + [commands addObject:pasteCommand]; + } +} + ++ (MPAutotypeCommand *)appendCommandForString:(NSString *)commandString toCommands:(NSMutableArray *)commands { + if(commandString) { + /* Find appropriate command */ + } } - (void)sendPressKey:(CGKeyCode)keyCode modifierFlags:(CGEventFlags)flags { diff --git a/MacPassTests/KPKTestAutotypeNormalization.m b/MacPassTests/KPKTestAutotypeNormalization.m index c7678af3..270f78f6 100644 --- a/MacPassTests/KPKTestAutotypeNormalization.m +++ b/MacPassTests/KPKTestAutotypeNormalization.m @@ -24,8 +24,14 @@ NSString *normalized = [@"Whoo %{% 2}{^}{SHIFT 5}+ {SPACE}{ENTER}^V%V~T" normalizedAutotypeSequence]; XCTAssertTrue([normalized isEqualToString:@"Whoo{SPACE}{ALT}{%}{%}{^}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SPACE}{SPACE}{ENTER}{CONTROL}V{ALT}V{ENTER}T"]); normalized = [@"{TAB 5}TAB{TAB}{SHIFT}{SHIFT 10}ENTER{ENTER}{%%}" normalizedAutotypeSequence]; - XCTAssertTrue(@"{TAB}{TAB}{TAB}{TAB}{TAB}TAB{TAB}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}ENTER{ENTER}{%%}"); + XCTAssertTrue([normalized isEqualToString:@"{TAB}{TAB}{TAB}{TAB}{TAB}TAB{TAB}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}ENTER{ENTER}{%%}"]); } +- (void)testeBracketValidation { + XCTAssertFalse([@"{BOOO}NO-COMMAND{TAB}{WHOO}{WHOO}{SPACE}!!!thisIsFun{{MISMATCH!!!}" validateCommmand]); + XCTAssertFalse([@"{{}}}}" validateCommmand]); + XCTAssertFalse([@"{}{}{{{}{{{{{{}}" validateCommmand]); + XCTAssertTrue([@"{}{}{}{}{}{ }ThisIsValid{}{STOP}" validateCommmand]); +} @end