diff --git a/src/aria2api.cc b/src/aria2api.cc index f922ee3c..27ed6680 100644 --- a/src/aria2api.cc +++ b/src/aria2api.cc @@ -481,7 +481,12 @@ const std::string& getGlobalOption(Session* session, const std::string& name) { const SharedHandle& e = session->context->reqinfo->getDownloadEngine(); - return e->getOption()->get(option::k2p(name)); + const Pref* pref = option::k2p(name); + if(OptionParser::getInstance()->find(pref)) { + return e->getOption()->get(pref); + } else { + return A2STR::NIL; + } } KeyVals getGlobalOptions(Session* session) @@ -776,7 +781,12 @@ struct RequestGroupDH : public DownloadHandle { } virtual const std::string& getOption(const std::string& name) { - return group->getOption()->get(option::k2p(name)); + const Pref* pref = option::k2p(name); + if(OptionParser::getInstance()->find(pref)) { + return group->getOption()->get(pref); + } else { + return A2STR::NIL; + } } virtual KeyVals getOptions() { diff --git a/test/Aria2ApiTest.cc b/test/Aria2ApiTest.cc index ac8eafb5..1dc5be42 100644 --- a/test/Aria2ApiTest.cc +++ b/test/Aria2ApiTest.cc @@ -179,6 +179,8 @@ void Aria2ApiTest::testChangeOption() CPPUNIT_ASSERT(std::find(retopts.begin(), retopts.end(), KeyVals::value_type("dir", "mydownload")) != retopts.end()); + // Don't return hidden option + CPPUNIT_ASSERT(hd->getOption(PREF_STARTUP_IDLE_TIME->k).empty()); deleteDownloadHandle(hd); // failure with null gid CPPUNIT_ASSERT_EQUAL(-1, changeOption(session_, (A2Gid)0, options)); @@ -205,7 +207,8 @@ void Aria2ApiTest::testChangeGlobalOption() CPPUNIT_ASSERT_EQUAL(0, changeGlobalOption(session_, options)); CPPUNIT_ASSERT_EQUAL(std::string("none"), getGlobalOption(session_, PREF_FILE_ALLOCATION->k)); - + // Don't return hidden option + CPPUNIT_ASSERT(getGlobalOption(session_, PREF_STARTUP_IDLE_TIME->k).empty()); // failure with bad option value options.clear(); options.push_back(KeyVals::value_type(PREF_FILE_ALLOCATION->k, "foo"));