diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_unittest.cc | 6 | ||||
-rw-r--r-- | chrome/browser/net/url_fixer_upper.cc | 57 | ||||
-rw-r--r-- | chrome/browser/net/url_fixer_upper.h | 1 |
3 files changed, 60 insertions, 4 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc index 1316eeb..eb15f2a 100644 --- a/chrome/browser/autocomplete/autocomplete_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_unittest.cc @@ -244,6 +244,12 @@ TEST(AutocompleteTest, InputType) { } } +// This tests for a regression where certain input in the omnibox caused us to +// crash. As long as the test completes without crashing, we're fine. +TEST(AutocompleteTest, InputCrash) { + AutocompleteInput input(L"\uff65@s", std::wstring(), true, false, false); +} + // Test that we can properly compare matches' relevance when at least one is // negative. TEST(AutocompleteMatch, MoreRelevant) { diff --git a/chrome/browser/net/url_fixer_upper.cc b/chrome/browser/net/url_fixer_upper.cc index d928c96..39ae80c 100644 --- a/chrome/browser/net/url_fixer_upper.cc +++ b/chrome/browser/net/url_fixer_upper.cc @@ -21,6 +21,53 @@ using namespace std; +namespace { + +// TODO(estade): Remove these ugly, ugly functions. They are only used in +// SegmentURL. A url_parse::Parsed object keeps track of a bunch of indices into +// a url string, and these need to be updated when the URL is converted from +// UTF8 to UTF16. Instead of this after-the-fact adjustment, we should parse it +// in the correct string format to begin with. +url_parse::Component UTF8ComponentToWideComponent( + string text_utf8, + const url_parse::Component& component_utf8) { + string before_component_string = text_utf8.substr(0, component_utf8.begin); + string component_string = text_utf8.substr(component_utf8.begin, + component_utf8.len); + wstring before_component_string_w = UTF8ToWide(before_component_string); + wstring component_string_w = UTF8ToWide(component_string); + url_parse::Component component_w(before_component_string_w.length(), + component_string_w.length()); + return component_w; +} + +void UTF8PartsToWideParts(string text_utf8, const url_parse::Parsed& parts_utf8, + url_parse::Parsed* parts) { + if (IsStringASCII(text_utf8)) { + *parts = parts_utf8; + return; + } + + parts->scheme = + UTF8ComponentToWideComponent(text_utf8, parts_utf8.scheme); + parts ->username = + UTF8ComponentToWideComponent(text_utf8, parts_utf8.username); + parts->password = + UTF8ComponentToWideComponent(text_utf8, parts_utf8.password); + parts->host = + UTF8ComponentToWideComponent(text_utf8, parts_utf8.host); + parts->port = + UTF8ComponentToWideComponent(text_utf8, parts_utf8.port); + parts->path = + UTF8ComponentToWideComponent(text_utf8, parts_utf8.path); + parts->query = + UTF8ComponentToWideComponent(text_utf8, parts_utf8.query); + parts->ref = + UTF8ComponentToWideComponent(text_utf8, parts_utf8.ref); +} + +} // namespace + // does some basic fixes for input that we want to test for file-ness static void PrepareStringForFileOps(const FilePath& text, FilePath::StringType* output) { @@ -469,14 +516,18 @@ string URLFixerUpper::FixupRelativeFile(const FilePath& base_dir, // Deprecated functions. To be removed when all callers are updated. wstring URLFixerUpper::SegmentURL(const wstring& text, url_parse::Parsed* parts) { - return UTF8ToWide(SegmentURL(WideToUTF8(text), parts)); + string text_utf8 = WideToUTF8(text); + url_parse::Parsed parts_utf8; + string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8); + UTF8PartsToWideParts(text_utf8, parts_utf8, parts); + return UTF8ToWide(scheme_utf8); } wstring URLFixerUpper::FixupURL(const wstring& text, - const wstring& desired_tld) { + const wstring& desired_tld) { return UTF8ToWide(FixupURL(WideToUTF8(text), WideToUTF8(desired_tld))); } wstring URLFixerUpper::FixupRelativeFile(const wstring& base_dir, - const wstring& text) { + const wstring& text) { return UTF8ToWide(FixupRelativeFile(FilePath::FromWStringHack(base_dir), FilePath::FromWStringHack(text))); } diff --git a/chrome/browser/net/url_fixer_upper.h b/chrome/browser/net/url_fixer_upper.h index 9e29e47..7b6332d 100644 --- a/chrome/browser/net/url_fixer_upper.h +++ b/chrome/browser/net/url_fixer_upper.h @@ -26,7 +26,6 @@ namespace URLFixerUpper { // Deprecated temporary compatibility function. std::wstring SegmentURL(const std::wstring& text, url_parse::Parsed* parts); - // Converts |text| to a fixed-up URL and returns it. Attempts to make // some "smart" adjustments to obviously-invalid input where possible. // |text| may be an absolute path to a file, which will get converted to a |