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

Side by Side 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, 2 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 , m_rewriteFolder(rewriteFolder) 246 , m_rewriteFolder(rewriteFolder)
247 { 247 {
248 } 248 }
249 249
250 void LinkChangeSerializerMarkupAccumulator::appendElement(StringBuilder& result, Element& element, Namespaces* namespaces) 250 void LinkChangeSerializerMarkupAccumulator::appendElement(StringBuilder& result, Element& element, Namespaces* namespaces)
251 { 251 {
252 if (element.hasTagName(HTMLNames::htmlTag)) { 252 if (element.hasTagName(HTMLNames::htmlTag)) {
253 // Add MOTW (Mark of the Web) declaration before html tag. 253 // Add MOTW (Mark of the Web) declaration before html tag.
254 // See http://msdn2.microsoft.com/en-us/library/ms537628(VS.85).aspx. 254 // See http://msdn2.microsoft.com/en-us/library/ms537628(VS.85).aspx.
255 result.append('\n'); 255 result.append('\n');
256 MarkupFormatter::appendComment(result, String::format(" saved from url=( %04d)%s ", 256 MarkupFormatter::appendComment(result, PageSerializer::markOfTheWebDecla ration(document().url()));
257 static_cast<int>(document().url().string().utf8().length()),
258 document().url().string().utf8().data()));
259 result.append('\n'); 257 result.append('\n');
260 } 258 }
261 259
262 if (element.hasTagName(HTMLNames::baseTag)) { 260 if (element.hasTagName(HTMLNames::baseTag)) {
263 // TODO(tiger): Refactor MarkupAccumulator so it is easier to append an element like this, without special cases for XHTML 261 // TODO(tiger): Refactor MarkupAccumulator so it is easier to append an element like this, without special cases for XHTML
264 // Append a new base tag declaration. 262 // Append a new base tag declaration.
265 result.appendLiteral("<base href=\".\""); 263 result.appendLiteral("<base href=\".\"");
266 if (!document().baseTarget().isEmpty()) { 264 if (!document().baseTarget().isEmpty()) {
267 result.appendLiteral(" target=\""); 265 result.appendLiteral(" target=\"");
268 MarkupFormatter::appendAttributeValue(result, document().baseTarget( ), document().isHTMLDocument()); 266 MarkupFormatter::appendAttributeValue(result, document().baseTarget( ), document().isHTMLDocument());
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 m_blankFrameURLs.add(frame, fakeURL); 568 m_blankFrameURLs.add(frame, fakeURL);
571 569
572 return fakeURL; 570 return fakeURL;
573 } 571 }
574 572
575 PageSerializer::Delegate* PageSerializer::delegate() 573 PageSerializer::Delegate* PageSerializer::delegate()
576 { 574 {
577 return m_delegate.get(); 575 return m_delegate.get();
578 } 576 }
579 577
578 // Returns MOTW (Mark of the Web) declaration before html tag which is in
579 // HTML comment, e.g. "<!-- saved from url=(%04d)%s -->"
580 // See http://msdn2.microsoft.com/en-us/library/ms537628(VS.85).aspx.
581 String PageSerializer::markOfTheWebDeclaration(const KURL& url)
582 {
583 StringBuilder builder;
584 bool emitsMinus = false;
585 CString orignalUrl = url.string().ascii();
586 for (const char* string = orignalUrl.data(); *string; ++string) {
587 const char ch = *string;
588 if (ch == '-' && emitsMinus) {
589 builder.append("%2D");
590 emitsMinus = false;
591 continue;
592 }
593 emitsMinus = ch == '-';
594 builder.append(ch);
595 }
596 CString escapedUrl = builder.toString().ascii();
597 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl .length()), escapedUrl.data());
598 }
599
580 } // namespace blink 600 } // namespace blink
OLDNEW
« 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