Skip to content

Commit 5491b4e

Browse files
committed
Updating uri_builder::append_query to use a switch statement and adding a test.
1 parent eca8ff7 commit 5491b4e

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Release/include/cpprest/uri_builder.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,19 @@ namespace web
244244
{
245245
auto encodingCheck = [](int ch)
246246
{
247-
// Encode '&', ';', and '=' since they are used
248-
// as delimiters in query component.
249-
return ch == '&' || ch == ';' || ch == '=' || !::web::details::uri_parser::is_query_character(ch)
250-
|| ch == '%' || ch == '+';
247+
switch (ch)
248+
{
249+
// Encode '&', ';', and '=' since they are used
250+
// as delimiters in query component.
251+
case '&':
252+
case ';':
253+
case '=':
254+
case '%':
255+
case '+':
256+
return true;
257+
default:
258+
return !::web::details::uri_parser::is_query_character(ch);
259+
}
251260
};
252261
encodedName = uri::encode_impl(encodedName, encodingCheck);
253262
encodedValue = uri::encode_impl(encodedValue, encodingCheck);

Release/tests/functional/uri/uri_builder_tests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,13 @@ TEST(append_query_string)
321321
VERIFY_ARE_EQUAL(U("key1=value1&key2=value2&key3=value3&key4=value4&key5=1&key6=val6&key%3D%26%3B=%3D%26%3Bvalue"), builder.query());
322322
}
323323

324+
TEST(append_query_string_no_encode)
325+
{
326+
uri_builder builder;
327+
builder.append_query(U("key=&;"), U("=&;value"), false);
328+
VERIFY_ARE_EQUAL(U("key=&;==&;value"), builder.query());
329+
}
330+
324331
TEST(append_string)
325332
{
326333
// with just path

0 commit comments

Comments
 (0)