Fixed stupid subclassing bug (and added test to avoid that in the future)

This commit is contained in:
relikd
2018-12-29 22:43:27 +01:00
parent 8fae59721b
commit 2732573003
7 changed files with 25 additions and 13 deletions

View File

@@ -201,7 +201,7 @@ static const NSInteger numberOfCharactersToSearch = 4096;
/// @return Kind of @c RSXMLParser or @c nil if no suitable parser found.
- (id)getParser {
return [[_parserClass alloc] initWithXMLData:self];
return [_parserClass parserWithXMLData:self];
}
/// @return @c YES if any parser, regardless of type, is suitable.

View File

@@ -51,8 +51,6 @@
+ (BOOL)isOPMLParser;
/// @return @c YES if parser supports parsing HTML files.
+ (BOOL)isHTMLParser;
/// Keeps an internal pointer to the @c RSXMLData and initializes a new @c RSSAXParser.
- (instancetype)initWithXMLData:(RSXMLData * _Nonnull)xmlData;
/// Will be called after the parsing is finished. @return Reference to parsed object.
- (id)xmlParserWillReturnDocument;
@end
@@ -61,6 +59,8 @@
@interface RSXMLParser<__covariant T> : NSObject <RSXMLParserDelegate, RSSAXParserDelegate>
@property (nonatomic, readonly, nonnull, copy) NSString *documentURI;
+ (instancetype)parserWithXMLData:(RSXMLData * _Nonnull)xmlData;
- (T _Nullable)parseSync:(NSError ** _Nullable)error;
- (void)parseAsync:(void(^)(T _Nullable parsedDocument, NSError * _Nullable error))block;
- (BOOL)canParse;

View File

@@ -43,6 +43,18 @@
/**
Designated initializer. Runs a check whether it matches the detected parser in @c RSXMLData.
Keeps an internal pointer to the @c RSXMLData and initializes a new @c RSSAXParser.
*/
+ (instancetype)parserWithXMLData:(nonnull RSXMLData *)xmlData {
if ([xmlData.parserClass isSubclassOfClass:[super class]]) {
return [[xmlData.parserClass alloc] initWithXMLData:xmlData];
}
return [[super alloc] initWithXMLData:xmlData];
}
/**
Internal initializer. Use the class initializer to automatically initialize to proper subclass.
Keeps an internal pointer to the @c RSXMLData and initializes a new @c RSSAXParser.
*/
- (instancetype)initWithXMLData:(nonnull RSXMLData *)xmlData {
self = [super init];
@@ -85,7 +97,6 @@
NSString *errMsg = [[NSString stringWithFormat:@"%s", msg] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
*error = [NSError errorWithDomain:kLIBXMLParserErrorDomain code:errCode userInfo:@{NSLocalizedDescriptionKey: errMsg}];
}
// *error = RSXMLMakeErrorFromLIBXMLError();
xmlResetLastError();
}
}