void build_path (array(string) path_segments) { path = map (path_segments, encode_reserved) * "/"; }
where encode_reserved only encodes the reserved chars and "%". Then the encoded_uri would do the rest of the job. E.g:
But why would this be better than
path = map (path_segments, encode) * "/";
where encode does all the job?
I don't understand what you mean with missing out on "%" there.
I mean that if a user uses a path with encoded "%"s in it without decoding it, he will not get the desired result, i.e. he misses out.
If you're suggesting that the user should simply join a fully decoded and splitted path using path*"/" then the only effect is that the user in his/hers own code reintroduces the ambiguity we're trying to avoid. That's not a solution.
Well, it depends on the context if this is the right thing to do or not, of course. If the encoded and unencoded /:s actually need to be handled differently in the application, then the user needs to do something anyway. If that something is simply to complain, then
Array.sum(map(path, has_value, "/"));
would do as a simple test. Depending on the situation there are other characters than "/" that you might want to treat specially. "\" for example, would introduce exactly the same ambiguity that you refer to if running on an NT system. So simply leaving "/" encoded does not really solve that problem.