summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorhayato@chromium.org <hayato@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-25 04:23:02 +0000
committerhayato@chromium.org <hayato@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-25 04:23:02 +0000
commitd09ef157bb44612d1bcd1bfe4e5fa26e1aaf0408 (patch)
tree28c7cfef4167ffddce1fcd0ebacc4ab83b5b33c9 /chrome
parent922dea0e0c86de952ae962127d3115234e277854 (diff)
downloadchromium_src-d09ef157bb44612d1bcd1bfe4e5fa26e1aaf0408.zip
chromium_src-d09ef157bb44612d1bcd1bfe4e5fa26e1aaf0408.tar.gz
chromium_src-d09ef157bb44612d1bcd1bfe4e5fa26e1aaf0408.tar.bz2
Ignore UTF-8's BOM when parsing userscript's metadata.
BUG=27333 TEST=UserScriptTest and check the issue does not happen against userscipt encoded in UTF-8 with BOM.. Review URL: http://codereview.chromium.org/420001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33048 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/user_script_master.cc7
-rw-r--r--chrome/browser/extensions/user_script_master_unittest.cc15
2 files changed, 21 insertions, 1 deletions
diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc
index c9228ff..a485a41 100644
--- a/chrome/browser/extensions/user_script_master.cc
+++ b/chrome/browser/extensions/user_script_master.cc
@@ -46,7 +46,12 @@ bool UserScriptMaster::ScriptReloader::ParseMetadataHeader(
// http://wiki.greasespot.net/Metadata_block
base::StringPiece line;
size_t line_start = 0;
- size_t line_end = 0;
+
+ // Skip UTF-8's BOM.
+ if (script_text.starts_with(kUtf8ByteOrderMark))
+ line_start += strlen(kUtf8ByteOrderMark);
+
+ size_t line_end = line_start;
bool in_metadata = false;
static const base::StringPiece kUserScriptBegin("// ==UserScript==");
diff --git a/chrome/browser/extensions/user_script_master_unittest.cc b/chrome/browser/extensions/user_script_master_unittest.cc
index 25ef7fc..6c01939 100644
--- a/chrome/browser/extensions/user_script_master_unittest.cc
+++ b/chrome/browser/extensions/user_script_master_unittest.cc
@@ -218,3 +218,18 @@ TEST_F(UserScriptMasterTest, Parse6) {
EXPECT_TRUE(UserScriptMaster::ScriptReloader::ParseMetadataHeader(
text, &script));
}
+
+TEST_F(UserScriptMasterTest, Parse7) {
+ const std::string text(
+ "\xEF\xBB\xBF// ==UserScript==\n"
+ "// @match http://*.mail.google.com/*\n"
+ "// ==/UserScript==\n");
+
+ // Should Ignore UTF-8's BOM.
+ UserScript script;
+ EXPECT_TRUE(UserScriptMaster::ScriptReloader::ParseMetadataHeader(
+ text, &script));
+ ASSERT_EQ(1U, script.url_patterns().size());
+ EXPECT_EQ("http://*.mail.google.com/*",
+ script.url_patterns()[0].GetAsString());
+}