summaryrefslogtreecommitdiffstats
path: root/net/base/escape.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-07 01:34:53 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-07 01:34:53 +0000
commitce85f60cd9d399109dab39fe5a9613879ab9a8f7 (patch)
tree0e9e0072d2e5eadfeec08eef0f06a43c56dc1751 /net/base/escape.cc
parentd90684d0cf0aa16389c9202153c97d373829b7f3 (diff)
downloadchromium_src-ce85f60cd9d399109dab39fe5a9613879ab9a8f7.zip
chromium_src-ce85f60cd9d399109dab39fe5a9613879ab9a8f7.tar.gz
chromium_src-ce85f60cd9d399109dab39fe5a9613879ab9a8f7.tar.bz2
Fix various problems with inline autocomplete and URLs that change length during fixup:
* URLs with http auth info, which gets stripped * URLs with IDN hosts * URLs with escaped values that get unescaped In cases like these, we'd inline autocomplete from the wrong locations, highlight the wrong portions of the URL as matches, and sometimes DCHECK() in debug mode. The fix is to track how fixup affects the offsets into the URL we care about. Plumbing this required an enormous number of additions :( There is also a fix here to the URL Fixer Upper, which was obviously modified at some point in the past to use the Parsed components, but without updating the comments or some of the functionality to match. Since this isn't supposed to "fix up" things that aren't simple typos, I removed some code to "fix" bogus ports, which was causing bizarre effects when typing HTTP auth URLs ("http://foo:bar" would be fixed to "http://foo" and then matched for inline autocompletion, which was clearly wrong). This is tested incidentally by one of the new History URL Provider tests (which is how I discovered it). BUG=4010 TEST=Covered by unittests Review URL: http://codereview.chromium.org/372017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31352 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/escape.cc')
-rw-r--r--net/base/escape.cc42
1 files changed, 33 insertions, 9 deletions
diff --git a/net/base/escape.cc b/net/base/escape.cc
index 3d2aca2..5196eb6 100644
--- a/net/base/escape.cc
+++ b/net/base/escape.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -107,7 +107,14 @@ const char kUrlUnescape[128] = {
};
std::string UnescapeURLImpl(const std::string& escaped_text,
- UnescapeRule::Type rules) {
+ UnescapeRule::Type rules,
+ size_t* offset_for_adjustment) {
+ size_t offset_temp = std::wstring::npos;
+ if (!offset_for_adjustment)
+ offset_for_adjustment = &offset_temp;
+ else if (*offset_for_adjustment >= escaped_text.length())
+ *offset_for_adjustment = std::wstring::npos;
+
// Do not unescape anything, return the |escaped_text| text.
if (rules == UnescapeRule::NONE)
return escaped_text;
@@ -136,8 +143,17 @@ std::string UnescapeURLImpl(const std::string& escaped_text,
// Additionally allow control characters if requested.
(value < ' ' && (rules & UnescapeRule::CONTROL_CHARS)))) {
// Use the unescaped version of the character.
+ size_t length_before_append = result.length();
result.push_back(value);
i += 2;
+
+ // Adjust offset to match length change.
+ if (*offset_for_adjustment != std::string::npos) {
+ if (*offset_for_adjustment > (length_before_append + 2))
+ *offset_for_adjustment -= 2;
+ else if (*offset_for_adjustment > length_before_append)
+ *offset_for_adjustment = std::string::npos;
+ }
} else {
// Keep escaped. Append a percent and we'll get the following two
// digits on the next loops through.
@@ -231,19 +247,27 @@ bool EscapeQueryParamValue(const std::wstring& text, const char* codepage,
return true;
}
-std::wstring UnescapeAndDecodeURLComponent(const std::string& text,
- const char* codepage,
- UnescapeRule::Type rules) {
+std::wstring UnescapeAndDecodeUTF8URLComponent(const std::string& text,
+ UnescapeRule::Type rules,
+ size_t* offset_for_adjustment) {
std::wstring result;
- if (base::CodepageToWide(UnescapeURLImpl(text, rules), codepage,
- base::OnStringConversionError::FAIL, &result))
+ size_t original_offset = offset_for_adjustment ? *offset_for_adjustment : 0;
+ if (base::CodepageToWideAndAdjustOffset(
+ UnescapeURLImpl(text, rules, offset_for_adjustment),
+ "UTF-8", base::OnStringConversionError::FAIL, &result,
+ offset_for_adjustment))
return result; // Character set looks like it's valid.
- return UTF8ToWide(text); // Return the escaped version when it's not.
+
+ // Not valid. Return the escaped version. Undo our changes to
+ // |offset_for_adjustment| since we haven't changed the string after all.
+ if (offset_for_adjustment)
+ *offset_for_adjustment = original_offset;
+ return UTF8ToWideAndAdjustOffset(text, offset_for_adjustment);
}
std::string UnescapeURLComponent(const std::string& escaped_text,
UnescapeRule::Type rules) {
- return UnescapeURLImpl(escaped_text, rules);
+ return UnescapeURLImpl(escaped_text, rules, NULL);
}
template <class str>