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

Unified Diff: third_party/WebKit/Source/core/page/PageSerializer.cpp

Issue 1371323003: Escape "--" in the page URL at page serialization (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2015-09-30T19:11:33 Follow review comments Created 5 years, 3 months 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
Index: third_party/WebKit/Source/core/page/PageSerializer.cpp
diff --git a/third_party/WebKit/Source/core/page/PageSerializer.cpp b/third_party/WebKit/Source/core/page/PageSerializer.cpp
index 96d4a4220cefb9f71e00401f2d79b9e7dd80b2b3..1bcf6a6a97d9db858175b36879d02342b66f1d84 100644
--- a/third_party/WebKit/Source/core/page/PageSerializer.cpp
+++ b/third_party/WebKit/Source/core/page/PageSerializer.cpp
@@ -253,9 +253,7 @@ void LinkChangeSerializerMarkupAccumulator::appendElement(StringBuilder& result,
// Add MOTW (Mark of the Web) declaration before html tag.
// See http://msdn2.microsoft.com/en-us/library/ms537628(VS.85).aspx.
result.append('\n');
- MarkupFormatter::appendComment(result, String::format(" saved from url=(%04d)%s ",
- static_cast<int>(document().url().string().utf8().length()),
- document().url().string().utf8().data()));
+ MarkupFormatter::appendComment(result, PageSerializer::markOfTheWebDeclaration(document().url()));
result.append('\n');
}
@@ -577,4 +575,26 @@ PageSerializer::Delegate* PageSerializer::delegate()
return m_delegate.get();
}
+// Returns MOTW (Mark of the Web) declaration before html tag which is in
+// HTML comment, e.g. "<!-- saved from url=(%04d)%s -->"
+// See http://msdn2.microsoft.com/en-us/library/ms537628(VS.85).aspx.
+String PageSerializer::markOfTheWebDeclaration(const KURL& url)
+{
+ StringBuilder builder;
+ bool emitsMinus = false;
+ CString orignalUrl = url.string().ascii();
+ for (const char* string = orignalUrl.data(); *string; ++string) {
+ const char ch = *string;
+ if (ch == '-' && emitsMinus) {
+ builder.append("%2D");
+ emitsMinus = false;
+ continue;
+ }
+ emitsMinus = ch == '-';
+ builder.append(ch);
+ }
+ CString escapedUrl = builder.toString().ascii();
+ return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl.length()), escapedUrl.data());
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/page/PageSerializer.h ('k') | third_party/WebKit/Source/web/WebPageSerializer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698