Skip to content
  • brettw's avatar
    Mark URLs with empty schemes as invalid. · 46f9b83f
    brettw authored
    Previously Chrome allowed empty schemes. This meant that URLs such as ":" or
    ":foo" were marked as valid.
    
    According to WHATWG:
      A scheme must be one ASCII alpha, followed by zero or more of ASCII
      alphanumeric, "+", "-", and ".".
    
    This change marks URLs with empty schemes as invalid.
    
    This forced some changes to the URL fixer and autocomplete systems to keep from breaking the behavior of input like ":w" (which we want to do a search). Previously the URL fixer would see ":w" as having a valid (but empty) scheme. Therefore, it would not attempt to prepend "http://" and the autocomplete system would make a GURL out of that literal string. GURL would interpret it as a "path" URL (with no host). AutocompleteInput::Parse checks for URLs with no host and a comment that this only happens for URLs beginning with a colon, and converts those to a query.
    
    With this change, ":w" becomes invalid and url_fixer attempts to prepend schemes. This changes the behavior for certain invalid URLs like ":b005::68]" in the tests which used to mean "give up" and now is treated like "http" like most other garbage input that doesn't start with a colon. For these types of inputs, I think either behavior should be fine.
    
    To preserve ":w" means query this patch just checks for a colon at the beginning of the input and removes the empty host check. I was originally trying to avoid this, but since there was already a special check for this unusual case, it seems inevitable that some check for this case will always be present.
    
    BUG=515497
    
    Review-Url: https://codereview.chromium.org/2378213002
    Cr-Commit-Position: refs/heads/master@{#423249}
    46f9b83f