Fix bug when handling extra long url (url longer than MAX_URL_LEN)

This commit is contained in:
Ai Lin Chia
2016-07-05 12:18:54 +02:00
parent d4094f7dcd
commit 4d01557b00
4 changed files with 32 additions and 6 deletions

11
Url.cpp

@ -1054,8 +1054,15 @@ void Url::set( const char *t, int32_t tlen, bool addWWW, bool stripParams, bool
}
// rebuild url
strcpy( s, urlParser.unparse() );
len = strlen(s);
urlParser.unparse();
len = urlParser.getUrlParsedLen();
if ( len > MAX_URL_LEN - 10 ) {
len = MAX_URL_LEN - 10;
}
strncpy( s, urlParser.getUrlParsed(), len );
s[len] = '\0';
}
// remove common filenames like index.html

@ -209,7 +209,9 @@ void UrlParser::parse() {
}
}
const char* UrlParser::unparse() {
/// @todo ALC a better way of doing this will be to check if the url has changed,
/// and call unparse automatically when getUrlParsed/getUrlParsedLen is called
void UrlParser::unparse() {
m_urlParsed.clear();
// domain
@ -247,8 +249,6 @@ const char* UrlParser::unparse() {
m_urlParsed.append( it->getString() );
}
}
return m_urlParsed.c_str();
}
void UrlParser::deleteComponent( UrlComponent *urlComponent ) {

@ -36,7 +36,7 @@ public:
bool removeQueryParam( const std::vector<UrlComponent*> &urlComponents, const UrlComponent::Validator &validator );
bool removeQueryParam( const UrlComponent::Matcher &keyMatch, const UrlComponent::Validator &validator );
const char* unparse();
void unparse();
// member access
const char* getUrl() const;
@ -56,6 +56,9 @@ public:
const std::vector<UrlComponent>* getPaths() const;
const std::vector<UrlComponent>* getQueries() const;
const char* getUrlParsed() const;
size_t getUrlParsedLen() const;
private:
void parse();
@ -136,4 +139,12 @@ inline const std::vector<UrlComponent>* UrlParser::getQueries() const {
return &m_queries;
}
inline const char* UrlParser::getUrlParsed() const {
return m_urlParsed.c_str();
}
inline size_t UrlParser::getUrlParsedLen() const {
return m_urlParsed.size();
}
#endif // GB_URLPARSER_H

File diff suppressed because one or more lines are too long