Fix crash when metaurl contains unsupported URI or text

pull/160/merge
Tatsuhiro Tsujikawa 2013-12-07 01:16:47 +09:00
parent 3096601ffe
commit 705dadb32b
4 changed files with 27 additions and 2 deletions

View File

@ -222,7 +222,7 @@ Metalink2RequestGroup::createRequestGroup
createRequestGroupForUri(result, optionTemplate, uris,
/* ignoreForceSequential = */true,
/* ignoreLocalPath = */true);
if(!uris.empty()) {
if(!result.empty()) {
torrentRg = result[0];
}
}

View File

@ -282,7 +282,8 @@ EXTRA_DIST = 4096chunk.txt\
metalink4-groupbymetaurl.xml\
serialize_session.meta4\
metalink4-dosdirtraversal.xml\
base_uri.xml
base_uri.xml\
local-metaurl.meta4
clean-local:
-rm -rf ${a2_test_outdir}

View File

@ -17,6 +17,7 @@ class Metalink2RequestGroupTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(Metalink2RequestGroupTest);
CPPUNIT_TEST(testGenerate);
CPPUNIT_TEST(testGenerate_with_local_metaurl);
CPPUNIT_TEST(testGenerate_groupByMetaurl);
CPPUNIT_TEST(testGenerate_dosDirTraversal);
CPPUNIT_TEST_SUITE_END();
@ -31,6 +32,7 @@ public:
}
void testGenerate();
void testGenerate_with_local_metaurl();
void testGenerate_groupByMetaurl();
void testGenerate_dosDirTraversal();
};
@ -125,6 +127,20 @@ void Metalink2RequestGroupTest::testGenerate()
}
}
void Metalink2RequestGroupTest::testGenerate_with_local_metaurl()
{
std::vector<std::shared_ptr<RequestGroup> > groups;
option_->put(PREF_DIR, "/tmp");
// local metaurl does not work without --metalink-base-uri option.
// Make sure that it does not crash with local metaurl.
Metalink2RequestGroup().generate(groups, A2_TEST_DIR"/local-metaurl.meta4",
option_);
CPPUNIT_ASSERT_EQUAL((size_t)1, groups.size());
CPPUNIT_ASSERT_EQUAL(std::string("http://example.org/README"),
groups[0]->getDownloadContext()->getFirstFileEntry()
->getRemainingUris()[0]);
}
void Metalink2RequestGroupTest::testGenerate_groupByMetaurl()
{
std::vector<std::shared_ptr<RequestGroup> > groups;

8
test/local-metaurl.meta4 Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<metalink xmlns="urn:ietf:params:xml:ns:metalink">
<file name="t/README">
<!-- require absolute URI here -->
<metaurl mediatype="torrent">README.torrent</metaurl>
<url type="http">http://example.org/README</url>
</file>
</metalink>