Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

href attributes need URI decoding

Two methods read "filenames" out of the OPF. These aren't filenames,
they're URIs and so need to be unescaped in order to be usable as
filenames in the zip.

NSString has a handy -stringByReplacingPercentEscapesUsingEncoding:
method which is used here.

The tests still all succeed. My book with a space in the cover image
filename now displays a cover image.
  • Loading branch information...
commit cfeca061fde3a1fe1757077d601fe100971b52f2 1 parent eba1657
@chrisridd authored
Showing with 10 additions and 9 deletions.
  1. +10 −9 JTPepub/JTPepub.m
View
19 JTPepub/JTPepub.m
@@ -151,7 +151,8 @@ - (NSString *)textFromManifestItem:(NSUInteger)n
return nil;
NSString *contentRoot = [rootFilePath stringByDeletingLastPathComponent];
- NSArray *textPathArray = [NSArray arrayWithObjects:contentRoot, [manifest objectAtIndex:n], nil];
+ NSString *relativePath = [[manifest objectAtIndex:n] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+ NSArray *textPathArray = [NSArray arrayWithObjects:contentRoot, relativePath, nil];
NSString *path = [NSString pathWithComponents:textPathArray];
NSData *content = [epubFile dataForNamedFile:path];
@@ -417,7 +418,7 @@ - (NSImage *)cover
NSError *xmlError = nil;
- NSString *coverPath = nil;
+ NSString *coverURI = nil;
//NSString *coverMIME = nil;
/*
@@ -436,7 +437,7 @@ - (NSImage *)cover
if (metaElements != nil) {
// There may only be one "cover-image" so take the last element of the array.
- coverPath = [[[metaElements lastObject] attributeForName:@"href"] stringValue];
+ coverURI = [[[metaElements lastObject] attributeForName:@"href"] stringValue];
//coverMIME = [[[metaElements lastObject] attributeForName:@"media-type"] stringValue];
@@ -448,8 +449,8 @@ - (NSImage *)cover
* not specified.
*/
- // Don't look for the coverPath if we already found it above.
- if (coverPath == nil) {
+ // Don't look for the coverURI if we already found it above.
+ if (coverURI == nil) {
// scan for a <meta> element with name="cover"
NSArray *metaElements = [opfXML nodesForXPath:@"//opf:meta"
namespaces:xmlns
@@ -483,7 +484,7 @@ - (NSImage *)cover
NSString *itemID = [[item attributeForName:@"id"] stringValue];
if([itemID caseInsensitiveCompare:coverID] == NSOrderedSame) {
- coverPath = [[item attributeForName:@"href"] stringValue];
+ coverURI = [[item attributeForName:@"href"] stringValue];
//coverMIME = [[item attributeForName:@"media-type"] stringValue];
break;
}
@@ -494,14 +495,14 @@ - (NSImage *)cover
* Image loading code is generic for epub2/3
*/
- if(coverPath == nil) {
+ if(coverURI == nil) {
haveCheckedForCover = YES;
return nil; // No cover in this epub.
}
-
-
+
// The cover path is relative to the rootfile...
NSString *contentRoot = [rootFilePath stringByDeletingLastPathComponent];
+ NSString *coverPath = [coverURI stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSArray *coverPathArray = [NSArray arrayWithObjects:contentRoot, coverPath, nil];
NSString *fullCoverPath = [NSString pathWithComponents:coverPathArray];
Please sign in to comment.
Something went wrong with that request. Please try again.