I really don't like this stuff.  You've already copied this block 3 times - I imagine there's a bunch of other places it will be needed as well.  We need to come up with a better solution rather than add all these "fixes" all over the show.

I think the only thing that will work is to never process paths directly based on their string representation.  Always use CURL objects that handle the encoding and decoding when converting to and from strings.  That way it's completely testable as well.  I think in addition you'd need the filename portion of the CURL stored as a vector of path portions.

In the meantime, I'll accept this change on 2 conditions:

1. You refactor the copy n paste to a separate helper (in the .cpp is fine - it obv. doesn't need exposing).
2. You provide tests to verify that your changes work.