From ef1ce4807490fd281e8322341d1c9bae6675b681 Mon Sep 17 00:00:00 2001 From: Zachary West Date: Sun, 22 Feb 2015 16:00:00 -0800 Subject: [PATCH] Fix tags with a space but no attributes to speak of --- Example/Tests/Tests/ZSWStringParserSpec.m | 6 ++++-- ZSWTaggedString/Private/ZSWStringParserTag.m | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Example/Tests/Tests/ZSWStringParserSpec.m b/Example/Tests/Tests/ZSWStringParserSpec.m index 99d7eed..e491adf 100644 --- a/Example/Tests/Tests/ZSWStringParserSpec.m +++ b/Example/Tests/Tests/ZSWStringParserSpec.m @@ -29,7 +29,7 @@ }).to.raise(NSInvalidArgumentException); }); }); - + __block id mockOptions; beforeEach(^{ @@ -92,7 +92,7 @@ }); it(@"should handle a string with multiple overlapping and non-overlapping tags", ^{ - ZSWTaggedString *taggedString = [ZSWTaggedString stringWithString:@"If I come without a thing, then I come with all I need"]; + ZSWTaggedString *taggedString = [ZSWTaggedString stringWithString:@"If I come without a thing, then I come with all I need"]; NSArray *tags; [[mockOptions expect] updateAttributedString:OCMOCK_ANY @@ -145,6 +145,8 @@ expect(tag.tagName).to.equal(@"hungry"); expect(tag.tagRange.location).to.equal(5); expect(tag.tagRange.length).to.equal(0); + + expect(tag.tagAttributes).to.equal(@{@"type": @"lol"}); }); }); diff --git a/ZSWTaggedString/Private/ZSWStringParserTag.m b/ZSWTaggedString/Private/ZSWStringParserTag.m index 44ba28a..272e25d 100644 --- a/ZSWTaggedString/Private/ZSWStringParserTag.m +++ b/ZSWTaggedString/Private/ZSWStringParserTag.m @@ -85,6 +85,11 @@ - (void)addRawTagAttributes:(NSString *)rawTagAttributes { // eat any whitespace at the start [scanner scanCharactersFromSet:whitespaceSet intoString:NULL]; + if (scanner.isAtEnd) { + // e.g., a tag like might produce just a space attribute + break; + } + // Scan up to '=' or ' ' NSString *attributeName; [scanner scanUpToCharactersFromSet:nameBreakSet intoString:&attributeName];