Skip to content

Percent encoding for different URI parts is different - take this into account when developing the pct_encode/pct_decode functions #157

Closed
glynos opened this Issue Oct 12, 2012 · 1 comment

1 participant

@glynos
C++ Network Library member
glynos commented Oct 12, 2012

Encoding for each URI part follows different rules, but the existing encode/decode functions don't consider this.

One solution might be to use a new parameter:

enum Part {
  Scheme, UserInfo, Host, Port, Path, Query, Fragment,
};

template <class String>
String network::pct_encode(const String &source, Part part);

Another solution might be to better parameterize the source to indicate to which part it belongs:

template <class String>
struct query_part_t {
   String source;
   query_part_t(const String &source) : source(source) {}
   void pct_encode() {
      ...
   }
};

template <class String>
query_part_t query(const String &source) {
  return query_part_t<String>(source);
}

template <class String>
String network::pct_encode(const query_part_t<String> &query) {
  query.pct_encode();
}


...

std::wstring encoded_query = network::pct_encode(query(L"key=value"));

Neither is completely generic. The second introduces more complexity, but is easier to read and to catch errors from the side of the user.

@glynos glynos was assigned Oct 12, 2012
@glynos
C++ Network Library member
glynos commented Jun 19, 2013

Yup, done.

@glynos glynos closed this Jun 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.