diff --git a/Frameworks/RSParser/Feeds/XML/RSAtomParser.m b/Frameworks/RSParser/Feeds/XML/RSAtomParser.m index 7783d90d9..fa326636d 100755 --- a/Frameworks/RSParser/Feeds/XML/RSAtomParser.m +++ b/Frameworks/RSParser/Feeds/XML/RSAtomParser.m @@ -15,6 +15,7 @@ #import #import #import +#import @interface RSAtomParser () @@ -34,6 +35,7 @@ @property (nonatomic) NSDate *dateParsed; @property (nonatomic) RSSAXParser *parser; @property (nonatomic, readonly) RSParsedArticle *currentArticle; +@property (nonatomic) RSParsedAuthor *currentAuthor; @property (nonatomic, readonly) NSDate *currentDate; @end @@ -128,6 +130,15 @@ static const NSInteger kUpdatedLength = 8; static const char *kAuthor = "author"; static const NSInteger kAuthorLength = 7; +static const char *kName = "name"; +static const NSInteger kNameLength = 5; + +static const char *kEmail = "email"; +static const NSInteger kEmailLength = 6; + +static const char *kURI = "uri"; +static const NSInteger kURILength = 4; + static const char *kEntry = "entry"; static const NSInteger kEntryLength = 6; @@ -404,6 +415,7 @@ static const NSInteger kLengthLength = 7; if (RSSAXEqualTags(localName, kAuthor, kAuthorLength)) { self.parsingAuthor = YES; + self.currentAuthor = [[RSParsedAuthor alloc] init]; return; } @@ -471,8 +483,25 @@ static const NSInteger kLengthLength = 7; [self.xhtmlString appendString:@">"]; } - else if (RSSAXEqualTags(localName, kAuthor, kAuthorLength)) { - self.parsingAuthor = NO; + else if (self.parsingAuthor) { + + if (RSSAXEqualTags(localName, kAuthor, kAuthorLength)) { + self.parsingAuthor = NO; + RSParsedAuthor *author = self.currentAuthor; + if (author.name || author.emailAddress || author.url) { + [self.currentArticle addAuthor:author]; + } + self.currentAuthor = nil; + } + else if (RSSAXEqualTags(localName, kName, kNameLength)) { + self.currentAuthor.name = self.parser.currentStringWithTrimmedWhitespace; + } + else if (RSSAXEqualTags(localName, kEmail, kEmailLength)) { + self.currentAuthor.emailAddress = self.parser.currentStringWithTrimmedWhitespace; + } + else if (RSSAXEqualTags(localName, kURI, kURILength)) { + self.currentAuthor.url = self.parser.currentStringWithTrimmedWhitespace; + } } else if (RSSAXEqualTags(localName, kEntry, kEntryLength)) { diff --git a/Frameworks/RSParser/RSParserTests/AtomParserTests.swift b/Frameworks/RSParser/RSParserTests/AtomParserTests.swift index 2f1a2bde3..2763c6912 100644 --- a/Frameworks/RSParser/RSParserTests/AtomParserTests.swift +++ b/Frameworks/RSParser/RSParserTests/AtomParserTests.swift @@ -54,6 +54,14 @@ class AtomParserTests: XCTestCase { XCTAssertTrue(article.uniqueID.hasPrefix("tag:daringfireball.net,2017:/")) XCTAssertEqual(article.authors!.count, 1) // TODO: parse Atom authors + let author = article.authors!.first! + if author.name == "Daring Fireball Department of Commerce" { + XCTAssertNil(author.url) + } + else { + XCTAssertEqual(author.name, "John Gruber") + XCTAssertEqual(author.url, "http://daringfireball.net/") + } XCTAssertNotNil(article.datePublished) XCTAssert(article.attachments == nil)