Modify

Ticket #5118 (closed Bugs: fixed)

Opened 3 years ago

Last modified 3 months ago

replace_extension doesn't work as specified in documentation

Reported by: bitfield.alex@… Owned by: bemandawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.45.0 Severity: Problem
Keywords: extension Cc: jonathan.jones@…

Description

  1. From Reference (see http://www.boost.org/doc/libs/1_45_0/libs/filesystem/v3/doc/reference.html#path-replace_extension):
path& replace_extension(const path& new_extension = path());

Postcondition: extension() == replacement, 
where replacement is new_extension 
  if new_extension.empty() || new_extension[0] == the dot character, 
otherwise replacement is the dot character followed by new_extension.

Returns: *this

Testing this behavior

path ph("foo.txt");
std::cout << ph.replace_extension("exe");

Output:

foo

Eather change the Reference or fix it in code.

  1. Current implementation doesn't allow to work with complex extentions.
path ph("foo.txt");
std::cout << ph.replace_extention(".tar.bz2");

Output:

foo.bz2
  1. There is no function to just add extension.

something like that:

path ph("foo.txt");
std::cout << ph.add_extension("bz2"); 

Expected output:

foo.txt.bz2

Attachments

replace_ext_fix.patch Download (721 bytes) - added by bitfield.alex@… 3 years ago.
Here is a patch for replace_extension method

Change History

comment:1 Changed 3 years ago by peter.baumann AT methodpark.de

This is also a regression from V2 -> V3, because in V2 this works as documented.

Changed 3 years ago by bitfield.alex@…

Here is a patch for replace_extension method

comment:2 Changed 3 years ago by anonymous

This bug is still in 1.47.0. Any hopes fixing it for the next release?

comment:3 Changed 2 years ago by anonymous

And it is still in 1.48.0
The "Boost Filesystem Do List" found in "boost_1_48_0/libs/filesystem/v3/doc/do_list.html" indicates that the behavior has changed from v2 to v3.

On the do list for documentation: Document behavior of path::replace_extension has change WRT argument w/o a dot.

Also, "boost_1_48_0/libs/filesystem/v3/test/path_test.cpp" includes multiple tests for this "new" functionality.

The documentation should be updated or the patch should be applied!

comment:4 Changed 2 years ago by cornedbee

Still in 1.49. This is a really nasty behavior change from v2.

comment:5 Changed 2 years ago by bemandawes

  • Status changed from new to closed
  • Resolution set to fixed

(In [77571]) Fix #5118, replace_extension doesn't work as specified in documentation

comment:6 Changed 2 years ago by bemandawes

The documentation, implementation, and test cases have all had fixes applied. The documentation had failed to mention that any existing extension is removed. The behavior for simple cases has been reverted to the Version 2 behavior, but with corrections so that complex replacements now work. Two test cases from #5118 have been added.

This ticket also includes a request for an "add_extension" function. That's been deferred since there is a pending request for += operator that would cover the requested functionality.

Thanks,

--Beman

comment:7 Changed 3 months ago by jonathan.jones@…

  • Cc jonathan.jones@… added
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.