mirror of
https://github.com/sogou/workflow.git
synced 2026-02-08 01:33:17 +08:00
fix password bug
This commit is contained in:
@@ -38,7 +38,7 @@ enum
|
||||
|
||||
//scheme://[userinfo@]host[:port][/path][?query][#fragment]
|
||||
//0-6 (scheme, userinfo, host, port, path, query, fragment)
|
||||
static constexpr unsigned char valid_char[URI_PART_ELEMENTS][256] = {
|
||||
static constexpr unsigned char valid_char[4][256] = {
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
@@ -111,60 +111,6 @@ static constexpr unsigned char valid_char[URI_PART_ELEMENTS][256] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
},
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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||||
},
|
||||
};
|
||||
|
||||
static unsigned char authority_map[256] = {
|
||||
@@ -205,62 +151,96 @@ static unsigned char path_map[256] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
void ParsedURI::__copy(const ParsedURI& copy)
|
||||
ParsedURI::ParsedURI(ParsedURI&& uri)
|
||||
{
|
||||
scheme = uri.scheme;
|
||||
userinfo = uri.userinfo;
|
||||
host = uri.host;
|
||||
port = uri.port;
|
||||
path = uri.path;
|
||||
query = uri.query;
|
||||
fragment = uri.fragment;
|
||||
state = uri.state;
|
||||
error = uri.error;
|
||||
uri.init();
|
||||
}
|
||||
|
||||
ParsedURI& ParsedURI::operator= (ParsedURI&& uri)
|
||||
{
|
||||
if (this != &uri)
|
||||
{
|
||||
deinit();
|
||||
scheme = uri.scheme;
|
||||
userinfo = uri.userinfo;
|
||||
host = uri.host;
|
||||
port = uri.port;
|
||||
path = uri.path;
|
||||
query = uri.query;
|
||||
fragment = uri.fragment;
|
||||
state = uri.state;
|
||||
error = uri.error;
|
||||
uri.init();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ParsedURI::copy(const ParsedURI& uri)
|
||||
{
|
||||
init();
|
||||
state = copy.state;
|
||||
error = copy.error;
|
||||
state = uri.state;
|
||||
error = uri.error;
|
||||
if (state == URI_STATE_SUCCESS)
|
||||
{
|
||||
bool succ = false;
|
||||
|
||||
do
|
||||
{
|
||||
if (copy.scheme)
|
||||
if (uri.scheme)
|
||||
{
|
||||
scheme = strdup(copy.scheme);
|
||||
scheme = strdup(uri.scheme);
|
||||
if (!scheme)
|
||||
break;
|
||||
}
|
||||
|
||||
if (copy.userinfo)
|
||||
if (uri.userinfo)
|
||||
{
|
||||
userinfo = strdup(copy.userinfo);
|
||||
userinfo = strdup(uri.userinfo);
|
||||
if (!userinfo)
|
||||
break;
|
||||
}
|
||||
|
||||
if (copy.host)
|
||||
if (uri.host)
|
||||
{
|
||||
host = strdup(copy.host);
|
||||
host = strdup(uri.host);
|
||||
if (!host)
|
||||
break;
|
||||
}
|
||||
|
||||
if (copy.port)
|
||||
if (uri.port)
|
||||
{
|
||||
port = strdup(copy.port);
|
||||
port = strdup(uri.port);
|
||||
if (!port)
|
||||
break;
|
||||
}
|
||||
|
||||
if (copy.path)
|
||||
if (uri.path)
|
||||
{
|
||||
path = strdup(copy.path);
|
||||
path = strdup(uri.path);
|
||||
if (!path)
|
||||
break;
|
||||
}
|
||||
|
||||
if (copy.query)
|
||||
if (uri.query)
|
||||
{
|
||||
query = strdup(copy.query);
|
||||
query = strdup(uri.query);
|
||||
if (!query)
|
||||
break;
|
||||
}
|
||||
|
||||
if (copy.fragment)
|
||||
if (uri.fragment)
|
||||
{
|
||||
fragment = strdup(copy.fragment);
|
||||
fragment = strdup(uri.fragment);
|
||||
if (!fragment)
|
||||
break;
|
||||
}
|
||||
@@ -367,9 +347,7 @@ int URIParser::parse(const char *str, ParsedURI& uri)
|
||||
break;
|
||||
|
||||
default:
|
||||
if (pre_state != URI_QUERY &&
|
||||
!valid_char[pre_state][(unsigned char)str[i]])
|
||||
return -1;//invalid char
|
||||
break;
|
||||
}
|
||||
|
||||
if (state >= URI_FRAGMENT)
|
||||
@@ -404,6 +382,13 @@ int URIParser::parse(const char *str, ParsedURI& uri)
|
||||
end_idx[pre_state] = i + strlen(str + i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < URI_QUERY; i++)
|
||||
{
|
||||
for (int j = start_idx[i]; j < end_idx[i]; j++)
|
||||
if (!valid_char[i][(unsigned char)str[j]])
|
||||
return -1;//invalid char
|
||||
}
|
||||
|
||||
char **dst[URI_PART_ELEMENTS] = {&uri.scheme, &uri.userinfo, &uri.host, &uri.port,
|
||||
&uri.query, &uri.fragment, &uri.path};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
limitations under the License.
|
||||
|
||||
Authors: Wu Jiaxu (wujiaxu@sogou-inc.com)
|
||||
Wang Zhulei (wangzhulei@sogou-inc.com)
|
||||
Wang Zhulei (wangzhulei@sogou-inc.com)
|
||||
*/
|
||||
|
||||
#ifndef _URIPARSER_H_
|
||||
@@ -53,53 +53,23 @@ public:
|
||||
virtual ~ParsedURI() { deinit(); }
|
||||
|
||||
//copy constructor
|
||||
ParsedURI(const ParsedURI& copy) { __copy(copy); }
|
||||
ParsedURI(const ParsedURI& uri) { copy(uri); }
|
||||
//copy operator
|
||||
ParsedURI& operator= (const ParsedURI& copy)
|
||||
ParsedURI& operator= (const ParsedURI& uri)
|
||||
{
|
||||
if (this != ©)
|
||||
if (this != &uri)
|
||||
{
|
||||
deinit();
|
||||
__copy(copy);
|
||||
copy(uri);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//move constructor
|
||||
ParsedURI(ParsedURI&& move)
|
||||
{
|
||||
scheme = move.scheme;
|
||||
userinfo = move.userinfo;
|
||||
host = move.host;
|
||||
port = move.port;
|
||||
path = move.path;
|
||||
query = move.query;
|
||||
fragment = move.fragment;
|
||||
state = move.state;
|
||||
error = move.error;
|
||||
move.init();
|
||||
}
|
||||
ParsedURI(ParsedURI&& uri);
|
||||
//move operator
|
||||
ParsedURI& operator= (ParsedURI&& move)
|
||||
{
|
||||
if (this != &move)
|
||||
{
|
||||
deinit();
|
||||
scheme = move.scheme;
|
||||
userinfo = move.userinfo;
|
||||
host = move.host;
|
||||
port = move.port;
|
||||
path = move.path;
|
||||
query = move.query;
|
||||
fragment = move.fragment;
|
||||
state = move.state;
|
||||
error = move.error;
|
||||
move.init();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
ParsedURI& operator= (ParsedURI&& uri);
|
||||
|
||||
private:
|
||||
void init()
|
||||
@@ -126,7 +96,7 @@ private:
|
||||
free(fragment);
|
||||
}
|
||||
|
||||
void __copy(const ParsedURI& copy);
|
||||
void copy(const ParsedURI& uri);
|
||||
};
|
||||
|
||||
// static class
|
||||
|
||||
@@ -54,7 +54,6 @@ foreach(src ${TEST_LIST})
|
||||
target_link_libraries(${src} ${WORKFLOW_LIB} GTest::GTest GTest::Main)
|
||||
add_test(${src} ${src})
|
||||
add_dependencies(check ${src})
|
||||
set_property(SOURCE ${src} APPEND PROPERTY COMPILE_OPTIONS "-fno-rtti")
|
||||
endforeach()
|
||||
|
||||
foreach(src ${TEST_LIST})
|
||||
|
||||
@@ -23,6 +23,15 @@ TEST(uriparser_unittest, parse)
|
||||
{
|
||||
ParsedURI uri;
|
||||
|
||||
EXPECT_EQ(URIParser::parse("https://john.doe:pass@www.example.com:123/forum/questions/?tag=networking&order=newest#top", uri), 0);
|
||||
EXPECT_EQ(strcmp(uri.scheme, "https"), 0);
|
||||
EXPECT_EQ(strcmp(uri.userinfo, "john.doe:pass"), 0);
|
||||
EXPECT_EQ(strcmp(uri.host, "www.example.com"), 0);
|
||||
EXPECT_EQ(strcmp(uri.port, "123"), 0);
|
||||
EXPECT_EQ(strcmp(uri.path, "/forum/questions/"), 0);
|
||||
EXPECT_EQ(strcmp(uri.query, "tag=networking&order=newest"), 0);
|
||||
EXPECT_EQ(strcmp(uri.fragment, "top"), 0);
|
||||
|
||||
EXPECT_EQ(URIParser::parse("https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top", uri), 0);
|
||||
EXPECT_EQ(strcmp(uri.scheme, "https"), 0);
|
||||
EXPECT_EQ(strcmp(uri.userinfo, "john.doe"), 0);
|
||||
|
||||
Reference in New Issue
Block a user