Skip to content

Commit

Permalink
Stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed May 6, 2017
1 parent f3c9e36 commit 487652a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/scripting/lua_fileops.cpp
Expand Up @@ -64,14 +64,13 @@ static std::string get_calling_file(lua_State* L)
/// @returns true if the filename was sucessfully resolved.
static bool resolve_filename(std::string& filename, std::string currentdir, std::string* rel = nullptr)
{
std::string p = filesystem::get_wml_location(filename, currentdir);
if(p.empty()) {
filename = filesystem::get_wml_location(filename, currentdir);
if(filename.empty()) {
return false;
}
if(rel) {
*rel = filesystem::get_short_wml_path(filename);
}
filename = p;
return true;
}

Expand Down
11 changes: 7 additions & 4 deletions src/tests/test_filesystem.cpp
Expand Up @@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE( test_fs_binary_path )
BOOST_CHECK_EQUAL( get_binary_dir_location("images", "."), gamedata + "/images/." );

BOOST_CHECK_EQUAL( get_binary_file_location("images", "././././././"),
gamedata + "/images/././././././" );
gamedata + "/images/" );

BOOST_CHECK_EQUAL( get_binary_file_location("images", "wesnoth-icon.png"),
gamedata + "/data/core/images/wesnoth-icon.png" );
Expand All @@ -157,14 +157,17 @@ BOOST_AUTO_TEST_CASE( test_fs_binary_path )
BOOST_CHECK_EQUAL( get_independent_image_path("wesnoth-icon.png"),
"data/core/images/wesnoth-icon.png" );

// Inexistent paths are resolved empty.
// Nonexistent paths are resolved empty.
BOOST_CHECK( get_binary_dir_location("images", "").empty() );
BOOST_CHECK( get_binary_dir_location("inexistent_resource_type", "").empty() );
BOOST_CHECK( get_binary_dir_location("nonexistent_resource_type", "").empty() );
BOOST_CHECK( get_binary_file_location("image", "wesnoth-icon.png").empty() );
BOOST_CHECK( get_binary_file_location("images", "bunnies_and_ponies_and_rainbows_oh_em_gee.psd").empty() );
BOOST_CHECK( get_binary_file_location("music", "this_track_does_not_exist.aiff").empty() );
BOOST_CHECK( get_binary_file_location("sounds", "rude_noises.aiff").empty() );
BOOST_CHECK( get_independent_image_path("dopefish.txt").empty() );

// Unsafe paths are resolved empty.
BOOST_CHECK()

This comment has been minimized.

Copy link
@jyrkive

jyrkive May 6, 2017

Member

?

This comment has been minimized.

Copy link
@CelticMinstrel

CelticMinstrel May 6, 2017

Author Member

Oh, I guess I committed something half-finished. Will fix. (This will be squashed, anyway.)

}

BOOST_AUTO_TEST_CASE( test_fs_wml_path )
Expand All @@ -187,7 +190,7 @@ BOOST_AUTO_TEST_CASE( test_fs_wml_path )
BOOST_CHECK_EQUAL(get_wml_location("./bats", get_wml_location("core/units")), gamedata + "/data/core/units/bats");
BOOST_CHECK_EQUAL(get_wml_location("../macros/ai.cfg", get_wml_location("core/units")), gamedata + "data/core/macros/ai.cfg");

// Inexistent paths are resolved empty.
// Nonexistent paths are resolved empty.
BOOST_CHECK( get_wml_location("why_would_anyone_ever_name_a_file_like_this").empty() );

// Unsafe paths are resolved empty.
Expand Down

0 comments on commit 487652a

Please sign in to comment.