Bug 1274602 - When checking for tags, allow for white-space. r=honzab
authorJorg K
Wed, 25 May 2016 05:56:00 -0400
changeset 337984 b050868120226fbcf67bf0c4d162755ea656f7ac
parent 337983 ae6c0fa8384e4bbdc12b0f5a19211a371259c23e
child 337985 915fe75544021565c55933cb978f858542a8babb
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs1274602
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1274602 - When checking for tags, allow for white-space. r=honzab
netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
--- a/netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
+++ b/netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
@@ -1223,62 +1223,68 @@ mozTXTToHTMLConv::ScanHTML(nsString& aIn
 #ifdef DEBUG_BenB_Perf
   PRTime parsing_start = PR_IntervalNow();
 #endif
 
   // Look for simple entities not included in a tags and scan them.
   // Skip all tags ("<[...]>") and content in an a link tag ("<a [...]</a>"),
   // comment tag ("<!--[...]-->"), style tag, script tag or head tag.
   // Unescape the rest (text between tags) and pass it to ScanTXT.
+  nsAutoCString canFollow(" \f\n\r\t>");
   for (int32_t i = 0; i < lengthOfInString;)
   {
     if (aInString[i] == '<')  // html tag
     {
       int32_t start = i;
-      if (Substring(aInString, i + 1, 2).LowerCaseEqualsASCII("a "))
+      if (i + 2 < lengthOfInString &&
+          nsCRT::ToLower(aInString[i + 1]) == 'a' &&
+          canFollow.FindChar(aInString[i + 2]) != kNotFound)
            // if a tag, skip until </a>.
-           // Make sure there's a space after, not to match "abbr".
+           // Make sure there's a white-space character after, not to match "abbr".
       {
         i = aInString.Find("</a>", true, i);
         if (i == kNotFound)
           i = lengthOfInString;
         else
           i += 4;
       }
       else if (Substring(aInString, i + 1, 3).LowerCaseEqualsASCII("!--"))
           // if out-commended code, skip until -->
       {
         i = aInString.Find("-->", false, i);
         if (i == kNotFound)
           i = lengthOfInString;
         else
           i += 3;
       }
-      else if (Substring(aInString, i + 1, 5).LowerCaseEqualsASCII("style") &&
-               (aInString.CharAt(i + 6) == ' ' || aInString.CharAt(i + 6) == '>'))
+      else if (i + 6 < lengthOfInString &&
+      Substring(aInString, i + 1, 5).LowerCaseEqualsASCII("style") &&
+               canFollow.FindChar(aInString[i + 6]) != kNotFound)
            // if style tag, skip until </style>
       {
         i = aInString.Find("</style>", true, i);
         if (i == kNotFound)
           i = lengthOfInString;
         else
           i += 8;
       }
-      else if (Substring(aInString, i + 1, 6).LowerCaseEqualsASCII("script") &&
-               (aInString.CharAt(i + 7) == ' ' || aInString.CharAt(i + 7) == '>'))
+      else if (i + 7 < lengthOfInString &&
+               Substring(aInString, i + 1, 6).LowerCaseEqualsASCII("script") &&
+               canFollow.FindChar(aInString[i + 7]) != kNotFound)
            // if script tag, skip until </script>
       {
         i = aInString.Find("</script>", true, i);
         if (i == kNotFound)
           i = lengthOfInString;
         else
           i += 9;
       }
-      else if (Substring(aInString, i + 1, 4).LowerCaseEqualsASCII("head") &&
-               (aInString.CharAt(i + 5) == ' ' || aInString.CharAt(i + 5) == '>'))
+      else if (i + 5 < lengthOfInString &&
+               Substring(aInString, i + 1, 4).LowerCaseEqualsASCII("head") &&
+               canFollow.FindChar(aInString[i + 5]) != kNotFound)
            // if head tag, skip until </head>
            // Make sure not to match <header>.
       {
         i = aInString.Find("</head>", true, i);
         if (i == kNotFound)
           i = lengthOfInString;
         else
           i += 7;