URI detection: sort results by match exactness

Not:

if URL == URI
   then return true
   else if host(URL) == host(URI)
      then return true
      else if basedomain(URL) == basedomain(URI)
         then return true
         else return false
      end
   end
end

Its a matching order rule:

  1. match with “exact”.
  2. match with “starts with”, with will consider the protocol (http, https, ftp, etc.), and the whole URI.
  3. match with “host”, this will consider subdomains (won’t include domain level records).
  4. match with “regex”, this can be optional.
  5. match with “Base domain”, this should include all related records for the domain.

Once there is a match, the corresponding records will be returned. Empty or wrong match is not a thing we need to consider, the user needs to modify the record to make it work, but I don’t think inthis way user will even have questions.

According to your pseudocode, it seems that bitwarden will perform marching one by one rather than global query, then for my idea, it should be:

func match
  if URL == URI
    return 1
  if URL.startswith(URI)
    return 2
  # if host(URL) == host(URI) and protocol same
  #  return x
  if host(URL) == host(URI)
    return 3
  if URI_REGEX.match(URL)
    # should sort domains for results
    return 4
  if basedomain(URL) == basedomain(URI)
    # should sort domains for results
    return 5
  retun 0

for res in vault:
  if match(res) > 0:
    results.add(res, level)

if results empty
  return empty
grouped = group_by_level(results)
for cur_level from levels 1..5
  if grouped.cur_level not empty
    return grouped.cur_level_res

retun empty

But I prefer:

rules = [
  query URI == URL
  query URL.startswith(URI)
  ...
]
for rule from rules
  res = run rule
  if res not empty
    return res
return empty

So if I have following records:

For visting sub.corp.com, I will get only one matched record “sub.corp.com”, rather than three (with base domain)

you can say now you can match with host, but we will need base domain match sometime, and we can’t choose it both, switching between them over and over again? Not a chance! :slight_smile:

For visiting x.corp.com, I will get both three

For this, if autofill could put “corp.com” record at the top, then it will be awesome!