Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Unified Diff: net/base/escape.cc

Issue 372017: Fix various problems with inline autocomplete and URLs that change length dur... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/escape.h ('k') | net/base/escape_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/escape.cc
===================================================================
--- net/base/escape.cc (revision 31214)
+++ net/base/escape.cc (working copy)
@@ -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 @@
};
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 @@
// 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 @@
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>
« no previous file with comments | « net/base/escape.h ('k') | net/base/escape_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698