Skip to content

Commit

Permalink
[Minor] Treat last dot specially
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Aug 10, 2023
1 parent d029c2a commit 0f36dc9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/libserver/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -2474,9 +2474,10 @@ rspamd_url_parse(struct rspamd_url *uri,
}
}

char last_c = rspamd_url_host_unsafe(uri)[uri->hostlen - 1];

if (all_chars_domain) {
/* Also check the last character to be either a dot or alphanumeric character */
char last_c = rspamd_url_host_unsafe(uri)[uri->hostlen - 1];
if (last_c != '.' && !g_ascii_isalnum(last_c)) {
all_chars_domain = false;
}
Expand All @@ -2485,7 +2486,15 @@ rspamd_url_parse(struct rspamd_url *uri,
if (all_chars_domain) {
/* Additionally check for a numeric IP as we can have some number here... */
rspamd_url_maybe_regenerate_from_ip(uri, pool);
uri->tldlen = uri->hostlen;

if (last_c == '.' && uri->hostlen > 1) {
/* Skip the last dot */
uri->tldlen = uri->hostlen - 1;
}
else {
uri->tldlen = uri->hostlen;
}

uri->tldshift = uri->hostshift;
is_whole_hostname_tld = true;
}
Expand Down
10 changes: 10 additions & 0 deletions test/lua/unit/url.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ context("URL check functions", function()
host = "63.143.41.164",
path = "pro/au.html",
} },
{
"http://localhost", true, {
host = "localhost",
tld = "localhost",
} },
{
"http://localhost.", true, {
host = "localhost.",
tld = "localhost",
} },
}

-- Some cases from https://code.google.com/p/google-url/source/browse/trunk/src/url_canon_unittest.cc
Expand Down

0 comments on commit 0f36dc9

Please sign in to comment.