Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix broken path handling when ncx file is at the root.

  • Loading branch information...
commit d4cf8babdecc147060bc8b32a178f8e9a1ad03e1 1 parent 8f048b1
Nathan Eror authored
2  EPUB3.c
@@ -1687,7 +1687,7 @@ char * EPUB3CopyOfPathByAppendingPathComponent(const char * path, const char * c
1687 1687
 
1688 1688
   EPUB3Bool shouldAddSeparator = kEPUB3_NO;
1689 1689
 
1690  
-  if(path[basePathLen - 1] != '/') {
  1690
+  if(basePathLen > 0 && path[basePathLen - 1] != '/') {
1691 1691
     shouldAddSeparator = kEPUB3_YES;
1692 1692
     basePathLen++;
1693 1693
   }
2  EPUB3Processor.xcodeproj/project.pbxproj
@@ -126,6 +126,7 @@
126 126
 		DF819DF715D4241E0074F9C2 /* EPUB3.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EPUB3.h; sourceTree = "<group>"; };
127 127
 		DF8CE03E15DEA03C00F0857B /* check_EPUB3_parsing.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = check_EPUB3_parsing.c; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.c; };
128 128
 		DF8CE04115DEA71000F0857B /* test_common.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = test_common.h; sourceTree = "<group>"; };
  129
+		DFA81D001652C15F00B9023D /* broken_medallion2.epub */ = {isa = PBXFileReference; lastKnownFileType = file; path = broken_medallion2.epub; sourceTree = "<group>"; };
129 130
 		DFFEB7E715F7E5BA0037977A /* pg100_cover.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = pg100_cover.jpg; sourceTree = "<group>"; };
130 131
 /* End PBXFileReference section */
131 132
 
@@ -314,6 +315,7 @@
314 315
 			children = (
315 316
 				DF1AD1701641944600690341 /* broken_medallion_1.ncx */,
316 317
 				DF1AD1711641944600690341 /* broken_medallion_1.opf */,
  318
+				DFA81D001652C15F00B9023D /* broken_medallion2.epub */,
317 319
 				DFFEB7E715F7E5BA0037977A /* pg100_cover.jpg */,
318 320
 				DF204B6015E69BFC00F0AA4D /* pg_100_content.opf */,
319 321
 				DF204B6215E69C1C00F0AA4D /* moby_dick_package.opf */,
BIN  TestEPUB3Processor/TestData/broken_medallion2.epub
Binary file not shown
55  TestEPUB3Processor/check_EPUB3_parsing.c
@@ -328,6 +328,60 @@ START_TEST(test_epub3_parse_data_from_opf_using_real_epub)
328 328
 }
329 329
 END_TEST
330 330
 
  331
+#pragma mark test_epub3_parse_data_from_opf_using_broken_medallion_epub
  332
+START_TEST(test_epub3_parse_data_from_opf_using_broken_medallion_epub)
  333
+{
  334
+  const char * expectedTitle = "A Lost Touch of Innocence";
  335
+  const char * expectedIdentifier = "978-1-60542-842-0";
  336
+  const char * expectedLanguage = "en-US";
  337
+
  338
+  const char * expItem1Id = "c01";
  339
+  const char * expItem1Href = "OEBPS/9781605428420_epub_c01_r1.htm";
  340
+  const char * expItem1MediaType = "application/xhtml+xml";
  341
+
  342
+  const char * expItem2Id = "css";
  343
+  const char * expItem2Href = "OEBPS/9781605428420_epub_css_r1.css";
  344
+  const char * expItem2MediaType = "text/css";
  345
+
  346
+  EPUB3Release(epub);
  347
+  TEST_PATH_VAR_FOR_FILENAME(path, "broken_medallion2.epub");
  348
+  TEST_DATA_FILE_SIZE_SANITY_CHECK(path, 2293984);
  349
+  epub = EPUB3Create();
  350
+  (void)EPUB3PrepareArchiveAtPath(epub, path);
  351
+
  352
+
  353
+  EPUB3Error error = EPUB3InitFromOPF(epub, "9781605428420_epub_opf_r1.opf");
  354
+  fail_unless(error == kEPUB3Success);
  355
+  fail_if(epub->metadata == NULL);
  356
+  fail_unless(epub->metadata->version == kEPUB3Version_2);
  357
+
  358
+  fail_if(epub->metadata->title == NULL, "A title is required by the EPUB 3 spec.");
  359
+  ck_assert_str_eq(epub->metadata->title, expectedTitle);
  360
+
  361
+  fail_if(epub->metadata->identifier == NULL, "An identifier is required by the EPUB 3 spec.");
  362
+  ck_assert_str_eq(epub->metadata->identifier, expectedIdentifier);
  363
+
  364
+  fail_if(epub->metadata->language == NULL, "A language is required by the EPUB 3 spec.");
  365
+  ck_assert_str_eq(epub->metadata->language, expectedLanguage);
  366
+
  367
+  EPUB3ManifestItemRef item = EPUB3ManifestCopyItemWithId(epub->manifest, expItem1Id);
  368
+  fail_if(item == NULL, "Could not fetch item with itemId %s from the manifest.", expItem1Id);
  369
+  assert(item != NULL);
  370
+  ck_assert_str_eq(item->itemId, expItem1Id);
  371
+  ck_assert_str_eq(item->href, expItem1Href);
  372
+  ck_assert_str_eq(item->mediaType, expItem1MediaType);
  373
+  EPUB3ManifestItemRelease(item);
  374
+
  375
+  item = EPUB3ManifestCopyItemWithId(epub->manifest, expItem2Id);
  376
+  fail_if(item == NULL, "Could not fetch item with itemId %s from the manifest.", expItem2Id);
  377
+  assert(item != NULL);
  378
+  ck_assert_str_eq(item->itemId, expItem2Id);
  379
+  ck_assert_str_eq(item->href, expItem2Href);
  380
+  ck_assert_str_eq(item->mediaType, expItem2MediaType);
  381
+  EPUB3ManifestItemRelease(item);
  382
+}
  383
+END_TEST
  384
+
331 385
 #pragma mark test_epub3_parse_manifest_from_shakespeare_opf_data
332 386
 START_TEST(test_epub3_parse_manifest_from_shakespeare_opf_data)
333 387
 {
@@ -638,6 +692,7 @@ TEST_EXPORT TCase * check_EPUB3_parsing_make_tcase(void)
638 692
   tcase_add_test(test_case, test_epub3_parse_metadata_from_shakespeare_opf_data);
639 693
   tcase_add_test(test_case, test_epub3_parse_metadata_from_moby_dick_opf_data);
640 694
   tcase_add_test(test_case, test_epub3_parse_data_from_opf_using_real_epub);
  695
+  tcase_add_test(test_case, test_epub3_parse_data_from_opf_using_broken_medallion_epub);
641 696
   tcase_add_test(test_case, test_epub3_parse_manifest_from_shakespeare_opf_data);
642 697
   tcase_add_test(test_case, test_epub3_parse_manifest_from_medallion_opf_data);
643 698
   tcase_add_test(test_case, test_epub3_parse_ncx_from_medallion);

0 notes on commit d4cf8ba

Please sign in to comment.
Something went wrong with that request. Please try again.