Opened 12 years ago

Closed 12 years ago

#4702 closed Bugs (fixed)

replace_extension truncates path

Reported by: cheesy4poofs@… Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.44.0 Severity: Problem
Keywords: replace_extension Cc:

Description

I've recently switched all our code to filesystem v3 and added BOOST_FILESYSTEM_NO_DEPRECATE on our builds for good measure. One of the changes I had to fix was our use of change_extension(), which was modified to use the replace_extension() method. However, some of our code started failing and I tracked it down to this example:

boost::filesystem::path p("C:
database
test
filename"); p.replace_extension(".db"); std::cout << p.string() << std::endl; OUTPUT - C:\database\test\filename.db

p = "C:
database.1
test
filename"; p.replace_extension(".db"); bug? std::cout << p.string() << std::endl; OUTPUT - C:\database.db

As you can see, in the second example, it truncates the path and assumes the directory name "database.1" has the extension that needs replacing. change_extension() did not behave this way.

Is this the expected behavior?

Change History (2)

comment:1 by anonymous, 12 years ago

Apparently, it didn't like the backslashes, let me try the examples again:

boost::filesystem::path p("/database/test/filename"); p.replace_extension(".db"); std::cout << p.string() << std::endl; OUTPUT - /database/test/filename.db

p = "/database.1/test/filename"; p.replace_extension(".db"); bug? std::cout << p.string() << std::endl; OUTPUT - /database.db

comment:2 by Beman Dawes, 12 years ago

Resolution: fixed
Status: newclosed

(In [65748]) Fix #4702

Note: See TracTickets for help on using tickets.