mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 08:12:28 +00:00
Updated normalization and validation test.
This commit is contained in:
Submodule KeePassKit updated: 7a4de6220e...1ec6abf2fa
@@ -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 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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user