Skip to content

cwk_path_is_absolute returns an incorrect result #24

@kampeador

Description

@kampeador

Hello.
Thanks for your library and putting a lot of effort into it.

I've made this simple unit test and 5 asserts have failed.

#ifdef _WIN32
  const bool is_unix = false;
  cwk_path_set_style(CWK_STYLE_WINDOWS);
#else
  const bool is_posix = true;
  cwk_path_set_style(CWK_STYLE_UNIX);
#endif

  assert( cwk_path_is_absolute("/") == is_unix  ); // fails
  assert( cwk_path_is_absolute("/dir") == is_unix  ); // fails
  assert( cwk_path_is_absolute("/dir/") == is_unix  ); // fails
  assert( cwk_path_is_absolute("/dir/tmp") == is_unix  ); // fails
  assert( cwk_path_is_absolute("/dir/tmp/") == is_unix  ); // fails
  assert( ! cwk_path_is_absolute("dir") );
  assert( ! cwk_path_is_absolute("dir/") );
  assert( ! cwk_path_is_absolute("dir/tmp") );
  assert( ! cwk_path_is_absolute("dir/tmp/") );
  assert( ! cwk_path_is_absolute("c:") );
  assert( ! cwk_path_is_absolute("c:dir") );
  assert( ! cwk_path_is_absolute("c:dir/") );
  assert( ! cwk_path_is_absolute("c:dir/tmp") );
  assert( ! cwk_path_is_absolute("c:dir/tmp/") );
  assert( cwk_path_is_absolute("c:/") == !is_unix  );
  assert( cwk_path_is_absolute("c:/dir") == !is_unix  );
  assert( cwk_path_is_absolute("c:/dir/") == !is_unix  );
  assert( cwk_path_is_absolute("c:/dir/tmp") == !is_unix  );
  assert( cwk_path_is_absolute("c:/dir/tmp/") == !is_unix  );

Windows also has a PathIsRelativeA/W function, which can be used as reference. However it has some limitations e.g MAX_PATH limit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions