Skip to content

Commit efc55da

Browse files
committed
Merge pull request #593 from barijaona/bugfixes
Prevent some crashes
2 parents 605346e + 7b84557 commit efc55da

15 files changed

+56
-73
lines changed

src/ActivityLog.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ -(void)sortUsingDescriptors:(NSArray *)sortDescriptors
219219
*/
220220
-(NSArray *)allItems
221221
{
222-
return [log copy];
222+
return log;
223223
}
224224

225225
/* dealloc

src/ActivityViewer.m

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ -(void)windowDidLoad
7777
-(BOOL)windowShouldClose:(NSNotification *)notification
7878
{
7979
[[Preferences standardPreferences] setObject:[splitView layout] forKey:@"SplitView3Positions"];
80+
[[NSNotificationCenter defaultCenter] removeObserver:self];
8081
return YES;
8182
}
8283

src/AppController.m

+5
Original file line numberDiff line numberDiff line change
@@ -611,11 +611,15 @@ -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
611611
NSLocalizedString(@"Cancel", nil),
612612
nil);
613613
if (returnCode == NSAlertAlternateReturn)
614+
{
615+
[[NSNotificationCenter defaultCenter] removeObserver:self];
614616
return NSTerminateCancel;
617+
}
615618
}
616619

617620
if (!didCompleteInitialisation)
618621
{
622+
[[NSNotificationCenter defaultCenter] removeObserver:self];
619623
return NSTerminateNow;
620624
}
621625

@@ -646,6 +650,7 @@ -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
646650
default: break;
647651
}
648652

653+
[[NSNotificationCenter defaultCenter] removeObserver:self];
649654
return NSTerminateNow;
650655
}
651656

src/ArticleListView.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ -(id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColum
16651665
}
16661666
else if ([identifier isEqualToString:MA_Field_Link])
16671667
{
1668-
cellString = [theArticle link];
1668+
cellString = SafeString([theArticle link]);
16691669
}
16701670
else if ([identifier isEqualToString:MA_Field_Subject])
16711671
{
@@ -1677,7 +1677,7 @@ -(id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColum
16771677
}
16781678
else if ([identifier isEqualToString:MA_Field_Enclosure])
16791679
{
1680-
cellString = [theArticle enclosure];
1680+
cellString = SafeString([theArticle enclosure]);
16811681
}
16821682
else
16831683
{

src/Folder.h

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
-(NSString *)lastUpdateString;
9494
-(NSString *)username;
9595
-(NSString *)password;
96-
-(NSDictionary *)attributes;
9796
-(NSArray *)articlesWithFilter:(NSString *)fstring;
9897
-(NSInteger)parentId;
9998
-(NSInteger)itemId;

src/Folder.m

-8
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,6 @@ -(NSInteger)childUnreadCount
155155
return childUnreadCount;
156156
}
157157

158-
/* attributes
159-
* Return the folder attributes.
160-
*/
161-
-(NSDictionary *)attributes
162-
{
163-
return [attributes copy];
164-
}
165-
166158
/* feedDescription
167159
* Returns the feed's description.
168160
*/

src/NewGroupFolder.m

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ -(IBAction)doSave:(id)sender
6464
canAppendIndex:NO];
6565

6666
// Close the window
67+
[[NSNotificationCenter defaultCenter] removeObserver:self];
6768
[NSApp endSheet:newGroupFolderWindow];
6869
[newGroupFolderWindow orderOut:self];
6970

@@ -76,6 +77,7 @@ -(IBAction)doSave:(id)sender
7677
*/
7778
-(IBAction)doCancel:(id)sender
7879
{
80+
[[NSNotificationCenter defaultCenter] removeObserver:self];
7981
[NSApp endSheet:newGroupFolderWindow];
8082
[newGroupFolderWindow orderOut:self];
8183
}

src/Preferences/AppearancePreferencesViewController.m

+10-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,16 @@ @implementation AppearancePreferencesViewController
4444

4545

4646
- (instancetype)init {
47-
return [super initWithNibName:@"AppearancePreferencesView" bundle:nil];
47+
if ((self = [super initWithNibName:@"AppearancePreferencesView" bundle:nil]) != nil)
48+
{
49+
// Set up to be notified if preferences change outside this window
50+
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
51+
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_FolderFontChange" object:nil];
52+
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_ArticleListFontChange" object:nil];
53+
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:kMA_Notify_MinimumFontSizeChange object:nil];
54+
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_PreferenceChange" object:nil];
55+
}
56+
return self;
4857
}
4958

5059

@@ -55,12 +64,6 @@ - (void)viewWillAppear {
5564
// Do view setup here.
5665
[self initializePreferences];
5766

58-
// Set up to be notified if preferences change outside this window
59-
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
60-
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_FolderFontChange" object:nil];
61-
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_ArticleListFontChange" object:nil];
62-
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:kMA_Notify_MinimumFontSizeChange object:nil];
63-
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_PreferenceChange" object:nil];
6467

6568
}
6669

src/Preferences/GeneralPreferencesViewController.m

+8-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ @implementation GeneralPreferencesViewController
3939

4040

4141
- (instancetype)init {
42-
return [super initWithNibName:@"GeneralPreferencesView" bundle:nil];
42+
if ((self = [super initWithNibName:@"GeneralPreferencesView" bundle:nil]) != nil)
43+
{
44+
// Set up to be notified if preferences change outside this window
45+
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
46+
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_CheckFrequencyChange" object:nil];
47+
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_PreferenceChange" object:nil];
48+
}
49+
return self;
4350
}
4451

4552

@@ -50,10 +57,6 @@ - (void)viewWillAppear {
5057

5158
[self initializePreferences];
5259

53-
// Set up to be notified if preferences change outside this window
54-
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
55-
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_CheckFrequencyChange" object:nil];
56-
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_PreferenceChange" object:nil];
5760
}
5861

5962

src/Preferences/SyncingPreferencesViewController.m

+11-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@ @implementation SyncingPreferencesViewController
3535

3636

3737
- (instancetype)init {
38-
return [super initWithNibName:@"SyncingPreferencesView" bundle:nil];
38+
if ((self = [super initWithNibName:@"SyncingPreferencesView" bundle:nil]) != nil)
39+
{
40+
// Set up to be notified if preferences change outside this window
41+
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
42+
[nc addObserver:self selector:@selector(handleGoogleAuthFailed:) name:@"MA_Notify_GoogleAuthFailed" object:nil];
43+
[nc addObserver:self selector:@selector(handleServerTextDidChange:) name:NSControlTextDidChangeNotification object:openReaderHost];
44+
[nc addObserver:self selector:@selector(handleUserTextDidChange:) name:NSControlTextDidChangeNotification object:username];
45+
[nc addObserver:self selector:@selector(handlePasswordTextDidChange:) name:NSControlTextDidEndEditingNotification object:password];
46+
}
47+
return self;
3948
}
4049

4150
- (void)viewWillAppear {
@@ -44,12 +53,6 @@ - (void)viewWillAppear {
4453
}
4554
// Do view setup here.
4655
sourcesDict = nil;
47-
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
48-
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
49-
[nc addObserver:self selector:@selector(handleGoogleAuthFailed:) name:@"MA_Notify_GoogleAuthFailed" object:nil];
50-
[nc addObserver:self selector:@selector(handleServerTextDidChange:) name:NSControlTextDidChangeNotification object:openReaderHost];
51-
[nc addObserver:self selector:@selector(handleUserTextDidChange:) name:NSControlTextDidChangeNotification object:username];
52-
[nc addObserver:self selector:@selector(handlePasswordTextDidChange:) name:NSControlTextDidEndEditingNotification object:password];
5356

5457
// restore from Preferences and from keychain
5558
Preferences * prefs = [Preferences standardPreferences];
@@ -268,6 +271,7 @@ -(void)handleGoogleAuthFailed:(NSNotification *)nc
268271

269272
-(void)dealloc
270273
{
274+
[[NSNotificationCenter defaultCenter] removeObserver:self];
271275
syncButton=nil;
272276
sourcesDict=nil;
273277

src/RenameFolder.m

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ -(IBAction)doRename:(id)sender
6161
if ([[folder name] isEqualToString:newName])
6262
{
6363
[renameFolderWindow orderOut:sender];
64+
[[NSNotificationCenter defaultCenter] removeObserver:self];
6465
[NSApp endSheet:renameFolderWindow returnCode:0];
6566
}
6667
else
@@ -71,6 +72,7 @@ -(IBAction)doRename:(id)sender
7172
{
7273
[db setFolderName:folderId newName:newName];
7374
[renameFolderWindow orderOut:sender];
75+
[[NSNotificationCenter defaultCenter] removeObserver:self];
7476
[NSApp endSheet:renameFolderWindow returnCode:1];
7577
}
7678
}
@@ -81,6 +83,7 @@ -(IBAction)doRename:(id)sender
8183
*/
8284
-(IBAction)doCancel:(id)sender
8385
{
86+
[[NSNotificationCenter defaultCenter] removeObserver:self];
8487
[NSApp endSheet:renameFolderWindow];
8588
[renameFolderWindow orderOut:self];
8689
}

src/StdEnclosureView.m

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#import "Preferences.h"
2323
#import "DownloadManager.h"
2424
#import "DSClickableURLTextField.h"
25+
#import "HelperFunctions.h"
2526

2627
// Private functions
2728
@interface StdEnclosureView (Private)
@@ -75,12 +76,17 @@ -(void)setEnclosureFile:(NSString *)newFilename
7576
FSRef appRef;
7677

7778
// Keep this for the download/open
78-
enclosureFilename = newFilename;
79+
enclosureFilename = [cleanedUpAndEscapedUrlFromString(newFilename) absoluteString];
7980

8081
NSString * basename = [[NSURL URLWithString:enclosureFilename] lastPathComponent];
8182
NSString * encodedname = [basename stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
8283
NSString * ext = [encodedname pathExtension];
8384

85+
if (basename==nil)
86+
{
87+
return;
88+
}
89+
8490
// Find the file's likely location in Finder and see if it is already there.
8591
// We'll set the options in the pane based on whether the file is there or not.
8692
NSString * destPath = [DownloadManager fullDownloadPath:encodedname];
@@ -166,6 +172,7 @@ -(void)drawRect:(NSRect)rect
166172
*/
167173
-(void)dealloc
168174
{
175+
[[NSNotificationCenter defaultCenter] removeObserver:self];
169176
enclosureFilename=nil;
170177
}
171178
@end

src/StringExtensions.h

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
+(NSString *)stringByRemovingHTML:(NSString *)theString;
3434
+(NSString *)mapEntityToString:(NSString *)entityString;
3535
+(NSString *)stringByConvertingHTMLEntities:(NSString *)stringToProcess;
36-
+(NSString * )stringByCleaningURLString:(NSString *) urlString;
3736
-(NSString *)firstNonBlankLine;
3837
-(NSString *)summaryTextFromHTML;
3938
-(NSString *)titleTextFromHTML;

src/StringExtensions.m

-36
Original file line numberDiff line numberDiff line change
@@ -756,40 +756,4 @@ +(NSString *)stringByConvertingHTMLEntities:(NSString *)stringToProcess
756756
return newString;
757757
}
758758

759-
/* stringByCleaningURLString
760-
* Percent escape invalid and reserved URL characters and return a legal URL string.
761-
* Better alternative to -stringByAddingPercentEscapesUsingEncoding:
762-
* Will handle unescaped or partially escaped URL strings where sequences are unpredictable,
763-
* for instance will preserve # announcing fragment from being escaped.
764-
* Uses WebKit to clean up user-entered URLs that might contain umlauts, diacritics and other
765-
* IDNA related stuff in the domain, or God knows what in filenames and arguments.
766-
*/
767-
+(NSString * )stringByCleaningURLString:(NSString *) urlString
768-
{
769-
NSString *newString;
770-
@try
771-
{
772-
NSPasteboard * pasteboard = [NSPasteboard pasteboardWithName:@"ViennaIDNURLPasteboard"];
773-
[pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
774-
if ([pasteboard setString:urlString forType:NSStringPboardType])
775-
newString = [[WebView URLFromPasteboard:pasteboard] absoluteString];
776-
else
777-
{
778-
newString = @"";
779-
// TODO: present error message to user?
780-
NSBeep();
781-
NSLog(@"Can't create URL from string '%@'.", urlString);
782-
}
783-
}
784-
@catch (NSException * exception)
785-
{
786-
newString = @"";
787-
// TODO: present error message to user?
788-
NSBeep();
789-
NSLog(@"Can't create URL from string '%@'.", urlString);
790-
}
791-
792-
return newString;
793-
}
794-
795759
@end

src/models/Article.m

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#import "Database.h"
2424
#import "StringExtensions.h"
2525
#import "CalendarExtensions.h"
26+
#import "HelperFunctions.h"
2627

2728
// The names here are internal field names, not for localisation.
2829
NSString * MA_Field_GUID = @"GUID";
@@ -243,7 +244,7 @@ -(NSString *)summary
243244
-(NSDate *)date { return [articleData objectForKey:MA_Field_Date]; }
244245
-(NSDate *)createdDate { return [articleData objectForKey:MA_Field_CreatedDate]; }
245246
-(NSString *)body { return [articleData objectForKey:MA_Field_Text]; }
246-
-(NSString *)enclosure { return [NSString stringByCleaningURLString:[articleData objectForKey:MA_Field_Enclosure]]; }
247+
-(NSString *)enclosure { return [articleData objectForKey:MA_Field_Enclosure]; }
247248

248249
/* containingFolder
249250
*/
@@ -311,7 +312,7 @@ -(NSScriptObjectSpecifier *)objectSpecifier
311312
*/
312313
-(NSString *)tagArticleLink
313314
{
314-
return [NSString stringByCleaningURLString:[self link]];
315+
return [cleanedUpAndEscapedUrlFromString([self link]) absoluteString];
315316
}
316317

317318
/* tagArticleTitle
@@ -360,7 +361,7 @@ -(NSString *)tagArticleDate
360361
*/
361362
-(NSString *)tagArticleEnclosureLink
362363
{
363-
return [self enclosure];
364+
return [cleanedUpAndEscapedUrlFromString([self enclosure]) absoluteString];
364365
}
365366

366367
/* tagArticleEnclosureFilename
@@ -386,7 +387,7 @@ -(NSString *)tagFeedTitle
386387
-(NSString *)tagFeedLink
387388
{
388389
Folder * folder = [[Database sharedManager] folderFromID:[self folderId]];
389-
return [NSString stringByCleaningURLString:[folder homePage]];
390+
return [cleanedUpAndEscapedUrlFromString([folder homePage]) absoluteString];
390391
}
391392

392393
/* tagFeedDescription

0 commit comments

Comments
 (0)