Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-18215] (3_5_X) iOS: App crashes while parsing XML #6510

Merged
merged 2 commits into from
Dec 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 13 additions & 21 deletions iphone/Classes/TiDOMElementProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,12 @@ -(id)insertBefore:(id)args
if (newNodePtr == refNodePtr)
return newChild;

TiDOMNodeListProxy* nodeList = [self childNodes];
[[self node]releaseCachedValues];
NSArray* theChildren = [[self node] children];


TiDOMNodeProxy* cur= nil;
int max = [TiUtils intValue:[nodeList length]];
BOOL found = NO;
for (int i=0; i<max && !found; i++) {
cur = (TiDOMNodeProxy*)[nodeList item:[NSNumber numberWithInt:i]];
if ([[cur node]XMLNode] == refNodePtr) {
for (GDataXMLNode* cur in theChildren) {
if ([cur XMLNode] == refNodePtr) {
found = YES;
}
}
Expand Down Expand Up @@ -625,15 +622,12 @@ -(id)replaceChild:(id)args
if (newNodePtr == refNodePtr)
return refChild;

TiDOMNodeListProxy* nodeList = [self childNodes];


TiDOMNodeProxy* cur= nil;
int max = [TiUtils intValue:[nodeList length]];
[[self node]releaseCachedValues];
NSArray* theChildren = [[self node] children];

BOOL found = NO;
for (int i=0; i<max && !found; i++) {
cur = (TiDOMNodeProxy*)[nodeList item:[NSNumber numberWithInt:i]];
if ([[cur node]XMLNode] == refNodePtr) {
for (GDataXMLNode* cur in theChildren) {
if ([cur XMLNode] == refNodePtr) {
found = YES;
}
}
Expand Down Expand Up @@ -677,13 +671,11 @@ -(id)removeChild:(id)args

xmlNodePtr refNodePtr = [[oldChild node]XMLNode];

TiDOMNodeListProxy* nodeList = [self childNodes];
TiDOMNodeProxy*cur = nil;
int max = [TiUtils intValue:[nodeList length]];
[[self node]releaseCachedValues];
NSArray* theChildren = [[self node] children];
BOOL found = NO;
for (int i=0; i<max && !found; i++) {
cur = (TiDOMNodeProxy*)[nodeList item:[NSNumber numberWithInt:i]];
if ([[cur node]XMLNode] == refNodePtr) {
for (GDataXMLNode* cur in theChildren) {
if ([cur XMLNode] == refNodePtr) {
found = YES;
}
}
Expand Down
6 changes: 3 additions & 3 deletions iphone/Classes/TiDOMNodeListProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
@interface TiDOMNodeListProxy : TiProxy {
@private
NSArray *nodes;
GDataXMLDocument* document;
}

@property(nonatomic,readonly) NSNumber *length;
-(void)setNodes:(NSArray*)nodes_;
-(id)item:(id)args;
-(NSNumber*)length;


-(id)_initWithPageContext:(id<TiEvaluator>)context nodes:(NSArray*)nodeList document:(GDataXMLDocument*)theDocument;

@end

#endif
#endif
45 changes: 20 additions & 25 deletions iphone/Classes/TiDOMNodeListProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@

@implementation TiDOMNodeListProxy

-(id)_initWithPageContext:(id<TiEvaluator>)context nodes:(NSArray*)nodeList document:(GDataXMLDocument*)theDocument;
{
if (self = [super _initWithPageContext:context]) {
nodes = [nodeList retain];
document = [theDocument retain];
}
return self;
}

-(void)dealloc
{
[nodes release];
[document release];
[super dealloc];
}

Expand All @@ -23,34 +33,19 @@ -(NSString*)apiName
return @"Ti.XML.NodeList";
}

-(void)setNodes:(NSArray*)nodes_
{
if (nodes == nodes_) {
return;
}
for (TiDOMNodeProxy *node in nodes) {
if (![nodes_ containsObject:node]) {
[self forgetProxy:node];
}
}
[nodes release];
nodes = [nodes_ retain];
for (TiDOMNodeProxy *node in nodes) {
[[self pageContext] registerProxy:node];
[self rememberProxy:node];
}
}

-(id)item:(id)args
{
ENSURE_SINGLE_ARG(args,NSObject);
int index = [TiUtils intValue:args];
ENSURE_SINGLE_ARG(args,NSObject);
int index = [TiUtils intValue:args];

if ( (index < [nodes count]) && (index >=0) )
{
return [nodes objectAtIndex:index];
}
return [NSNull null];
if ( (index < [nodes count]) && (index >=0) ) {
GDataXMLNode* theNode = [nodes objectAtIndex:index];
id context = ([self executionContext]==nil)?[self pageContext]:[self executionContext];
id nodeProxy = [TiDOMNodeProxy makeNode:theNode context:context];
[(TiDOMNodeProxy*)nodeProxy setDocument:document];
return nodeProxy;
}
return [NSNull null];
}

-(NSNumber*)length
Expand Down
13 changes: 1 addition & 12 deletions iphone/Classes/TiDOMNodeProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,7 @@ +(void)removeNodeForXMLNode:(xmlNodePtr)nodePtr

-(id)makeNodeListProxyFromArray:(NSArray*)nodes context:(id<TiEvaluator>)context
{
NSMutableArray *proxyArray = nil;
if (nodes != nil) {
proxyArray = [NSMutableArray array];
for (GDataXMLNode* child in nodes) {
[proxyArray addObject:[self makeNode:child context:context]];
}
}

TiDOMNodeListProxy *proxy = [[[TiDOMNodeListProxy alloc] _initWithPageContext:context] autorelease];
[proxy setNodes:proxyArray];
return proxy;

return [[[TiDOMNodeListProxy alloc] _initWithPageContext:context nodes:nodes document:[self document]] autorelease];
}

+(void)validateAttributeParameters:(NSString*)tagName withUri:(NSString*)theURI reason:(NSString**)error subreason:(NSString**)suberror
Expand Down