url icon indicating copy to clipboard operation
url copied to clipboard

Assigning segments_ref to segments_ref

Open vinniefalco opened this issue 3 years ago • 4 comments

Consider the following:

url u1( "/index%2Ehtm" );
url u2( "/path/to/file%2Etxt" );
segments_ref ps1 = u1.segments();
segments_ref Type ps2 = u2.segments();
ps1 = p2;

What should the contents of ps1 be? Well, operator= is documented with this effect:

ps1.assign( ps2.begin(), p2.end() );

Iterating ps2 will produce decoded segments, so ps1 will end up with

{ "path", "to", "file.txt" }

Note how "file.txt" has the escape removed. This behavior is technically correct according to our specification but is this the right thing to do?

vinniefalco avatar Sep 09 '22 02:09 vinniefalco

@pdimov any idears?

vinniefalco avatar Sep 11 '22 23:09 vinniefalco

Yes it's the right thing to do.

pdimov avatar Sep 12 '22 07:09 pdimov

Even more interesting is u1.segments() = u1.segments();, which should do the same (that is, remove any unnecessary percent encoding.)

Not sure about u1.segments().back() = u1.segments().back();. Does this work?

pdimov avatar Sep 12 '22 07:09 pdimov

Not sure about u1.segments().back() = u1.segments().back();. Does this work?

No, because back() just returns a string. Assignment can't work for elements, since iterators don't return modifiable references to the underlying element.

vinniefalco avatar Sep 12 '22 12:09 vinniefalco