Skip to content

Commit

Permalink
Merge pull request #12 from russellmcc/fix_userinfo
Browse files Browse the repository at this point in the history
Fix userinfo parsing
  • Loading branch information
chmike authored Sep 30, 2021
2 parents 1cfabfb + 5ccee82 commit 2c8cf9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@

using namespace std;

#define test_parse(str, m, expect) {\
try {\
Url url(str);\
if(url.m()!=expect)\
cout << "FAILED: ('" << str << "') -> "#m"('" << url.m() << "') (expect " << expect << ")" << endl;\
else\
cout << "PASSED: ('" << str << "') -> "#m"('" << url.m() << "')" << endl;\
} catch(std::exception &e) {\
cout << "FAILED: ('" << str << "') -> \"" << e.what() << "\" (expect " << expect << ")" << endl;\
}\
}


#define test_valid(m1,str,m2,expect,ip_v) {\
Expand Down Expand Up @@ -56,6 +67,7 @@ void test_all_valid() {
cout << "------------------------------------------------------" << endl;
test_valid(user_info,"",user_info,"",-1);
test_valid(user_info,"user:passwd",user_info,"user:passwd",-1);
test_parse("http://user:pa%24%[email protected]",user_info,"user:pa$$wd");

cout << "------------------------------------------------------" << endl;
cout << "Test host" << endl;
Expand Down
2 changes: 1 addition & 1 deletion url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ void Url::parse_url() const {
p=find_char(b, ea, '@');
// get user info if any
if (p!=ea) {
if (!is_chars(b, p, 0x05))
if (!is_chars(b, p, 0x25))
throw Url::parse_error("User info in '"+std::string(s,e-s)+"' is invalid");
user_b=b;
user_e=p;
Expand Down

0 comments on commit 2c8cf9a

Please sign in to comment.