Opened 12 years ago

Closed 8 years ago

#4329 closed Bugs (fixed)

filesystem::basename is completely erratic

Reported by: Richard B. Kreckel <kreckel@…> Owned by: Beman Dawes
Milestone: Boost 1.43.0 Component: filesystem
Version: Boost 1.44.0 Severity: Problem
Keywords: Cc: kreckel@…

Description

The attached program shows that basename is broken. I've tried 1.33.1, where it prints (as I would have expected):

a a b b c c d d e e

Using 1.35.0, 1.40.0, 1.42.0, it prints:

a b / c d e

Observe the exceptional behavior of basename("a/b/") returning "/".

IMHO, basename's behaviour shouldn't differ from Posix's basename.

Attachments (1)

fs.cc (681 bytes ) - added by Richard B. Kreckel <kreckel@…> 12 years ago.

Download all attachments as: .zip

Change History (3)

by Richard B. Kreckel <kreckel@…>, 12 years ago

Attachment: fs.cc added

comment:1 by anonymous, 12 years ago

Reproducible on Debian GNU/Linux kernel 2.6.32-3-amd64. According to the filesystem documentation, though, basename is a deprecated convenience function.

comment:2 by Beman Dawes, 8 years ago

Resolution: fixed
Status: newclosed

Sorry for the delay in closing this issue. The function is now a member of path, and has been renamed stem(). The actual problem was fixed years ago.

A reworked version of the test program was tested against the current version of the library:

#include <iostream>
#include <boost/filesystem.hpp>
using boost::filesystem::path;

int main()
{
  std::cout << path("a").stem() << std::endl;
  std::cout << path("a/").stem() << std::endl;
  std::cout << path("a/b").stem() << std::endl;
  std::cout << path("a/b/").stem() << std::endl;
  std::cout << path("a/b/c").stem() << std::endl;
  std::cout << path("a/b/c/").stem() << std::endl;
  std::cout << path("a/b/c/d").stem() << std::endl;
  std::cout << path("a/b/c/d/").stem() << std::endl;
  std::cout << path("a/b/c/d/e").stem() << std::endl;
  std::cout << path("a/b/c/d/e/").stem() << std::endl;
  return 0;
}

Output:

"a"
"."
"b"
"."
"c"
"."
"d"
"."
"e"
"."

That is the expected output according to the C++ Filesystem TS, which is now the base document for boost.filesystem.

Thanks,

--Beman

Note: See TracTickets for help on using tickets.