forked from Mirrors/privacore-open-source-search-engine
Fix bug when handling extra long url (url longer than MAX_URL_LEN)
This commit is contained in:
11
Url.cpp
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 ) {
|
||||
|
13
UrlParser.h
13
UrlParser.h
@ -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
Reference in New Issue
Block a user