Skip to content

Commit

Permalink
fix(sanitize): extract authority
Browse files Browse the repository at this point in the history
fix #809
  • Loading branch information
alandefreitas committed Jan 3, 2024
1 parent 2df5f62 commit 6cebc9b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions example/sanitize/sanitize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,14 @@ extract_uri_components(
url_components &out)
{
if (s.starts_with("//") && !s.starts_with("///"))
{
return extract_scheme_relative(s.substr(2), out);
}

if (s.starts_with('/'))
{
return extract_relative_ref(s, out);
}

// extract scheme
// first char in a scheme must be letter (we accept uppercase here)
Expand All @@ -289,9 +293,17 @@ extract_uri_components(
// The usual route, parse scheme first
core::string_view scheme_relative = s;
if (has_scheme)
{
scheme_relative = s.substr(out.scheme.size() + 1);
}

const bool has_authority = scheme_relative.starts_with("//");
if (has_authority)
{
scheme_relative = scheme_relative.substr(2);
return extract_scheme_relative(scheme_relative, out);
}

const bool is_relative_ref = !has_scheme && !has_authority;
if (is_relative_ref)
{
Expand Down Expand Up @@ -320,9 +332,6 @@ extract_uri_components(
return extract_relative_ref(s, out);
}

if (has_authority)
scheme_relative = scheme_relative.substr(2);

// all that's left is a relative path
return extract_relative_ref(scheme_relative, out);
}
Expand Down

0 comments on commit 6cebc9b

Please sign in to comment.