Skip to content

Commit

Permalink
Removed obsolete code from normalize_link()
Browse files Browse the repository at this point in the history
Current version of normalize_link() discards the query and/or fragment
components of a URL.
  • Loading branch information
veloman-yunkan committed Nov 14, 2023
1 parent 6f5bd55 commit 56b7ce5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ std::string normalize_link(const std::string& input, const std::string& baseUrl)
std::string output;
output.reserve(baseUrl.size() + input.size() + 1);

bool in_query = false;
bool check_rel = false;
const char* p = input.c_str();
if ( *(p) == '/') {
Expand All @@ -420,7 +419,7 @@ std::string normalize_link(const std::string& input, const std::string& baseUrl)
//URL Decoding.
while (*p)
{
if ( !in_query && check_rel ) {
if ( check_rel ) {
if (strncmp(p, "../", 3) == 0) {
// We must go "up"
// Remove the '/' at the end of output.
Expand All @@ -441,9 +440,13 @@ std::string normalize_link(const std::string& input, const std::string& baseUrl)
continue;
}
}
if ( *p == '#' || *p == '?')
// This is a beginning of the #anchor inside a page. No need to decode more

if ( *p == '#' || *p == '?') {
// For our purposes we can safely discard the query and/or fragment
// components of the URL
break;
}

if ( *p == '%')
{
char ch;
Expand All @@ -452,10 +455,7 @@ std::string normalize_link(const std::string& input, const std::string& baseUrl)
p += 3;
continue;
}
if ( *p == '?' ) {
// We are in the query, so don't try to interprete '/' as path separator
in_query = true;
}

if ( *p == '/') {
check_rel = true;
if (output.empty()) {
Expand Down

0 comments on commit 56b7ce5

Please sign in to comment.