# HG changeset patch
# User Jorg K
# Date 1464170160 14400
#      Wed May 25 05:56:00 2016 -0400
# Branch THUNDERBIRD3880_2016050308_RELBRANCH
# Node ID c55562b24ecf9b36b9200344ad3cb96b6084ae1f
# Parent  7dc4e33ecec29eebbd7329e08a2ba79b0b6f0a6b
Bug 1274602 - When checking for tags, allow for white-space. r=honzab a=rkent

diff --git a/netwerk/streamconv/converters/mozTXTToHTMLConv.cpp b/netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
--- a/netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
+++ b/netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
@@ -1220,62 +1220,68 @@
 #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;
