Skip to content

Commit

Permalink
Fix tags with a space but no attributes to speak of
Browse files Browse the repository at this point in the history
  • Loading branch information
zacwest committed Feb 23, 2015
1 parent a9eb47d commit ef1ce48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Example/Tests/Tests/ZSWStringParserSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}).to.raise(NSInvalidArgumentException);
});
});

__block id mockOptions;

beforeEach(^{
Expand Down Expand Up @@ -92,7 +92,7 @@
});

it(@"should handle a string with multiple overlapping and non-overlapping tags", ^{
ZSWTaggedString *taggedString = [ZSWTaggedString stringWithString:@"<all><qual>If I come <sad>without</sad> a thing</qual>, <suppose>then I come with <happy>all</happy> I need</suppose></all>"];
ZSWTaggedString *taggedString = [ZSWTaggedString stringWithString:@"<all><qual>If I come <sad >without</sad> a thing</qual>, <suppose >then I come with <happy>all</happy> I need</suppose></all>"];

NSArray *tags;
[[mockOptions expect] updateAttributedString:OCMOCK_ANY
Expand Down Expand Up @@ -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"});
});
});

Expand Down
5 changes: 5 additions & 0 deletions ZSWTaggedString/Private/ZSWStringParserTag.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dog ></dog> might produce just a space attribute
break;
}

// Scan up to '=' or ' '
NSString *attributeName;
[scanner scanUpToCharactersFromSet:nameBreakSet intoString:&attributeName];
Expand Down

0 comments on commit ef1ce48

Please sign in to comment.