>From 3901f96fc1b359c5e409a2dd8246ef862f778994 Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov@codeweavers.com>
Date: Sun, 29 Jan 2012 23:33:04 +0300
Subject: [PATCH 7/7] Recognize <head> start tag as text/html MIME type

---
 dlls/urlmon/tests/misc.c  |   10 +++++++++-
 dlls/urlmon/urlmon_main.c |   20 +++++++++++++-------
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/dlls/urlmon/tests/misc.c b/dlls/urlmon/tests/misc.c
index ea634c1..bbb657f 100644
--- a/dlls/urlmon/tests/misc.c
+++ b/dlls/urlmon/tests/misc.c
@@ -563,6 +563,10 @@ static BYTE data83[] = {'.','s','n','d'};
 static BYTE data84[] = {'.','s','n','d',0,'<','h','t','m','l','>',1,1};
 static BYTE data85[] = {'.','S','N','D',0};
 static BYTE data86[] = {0x49,0x49,0x2a,0xff};
+static BYTE data87[] = {' ','<','h','e','a','d'};
+static BYTE data88[] = {' ','<','h','e','a','d','>'};
+static BYTE data89[] = {'\t','\r','<','h','e','a','d','>'};
+static BYTE data90[] = {'<','H','e','A','d','>'};
 
 static const struct {
     BYTE *data;
@@ -654,7 +658,11 @@ static const struct {
     {data83, sizeof(data83), mimeTextPlain},
     {data84, sizeof(data84), mimeTextHtml, mimeAudioBasic /* IE8 */},
     {data85, sizeof(data85), mimeTextPlain},
-    {data86, sizeof(data86), mimeImageTiff, NULL, mimeTextPlain}
+    {data86, sizeof(data86), mimeImageTiff, NULL, mimeTextPlain},
+    {data87, sizeof(data87), mimeTextPlain},
+    {data88, sizeof(data88), mimeTextHtml, mimeTextPlain /* IE8 */},
+    {data89, sizeof(data89), mimeTextHtml, mimeTextPlain /* IE8 */},
+    {data90, sizeof(data90), mimeTextHtml, mimeTextPlain /* IE8 */}
 };
 
 static void test_FindMimeFromData(void)
diff --git a/dlls/urlmon/urlmon_main.c b/dlls/urlmon/urlmon_main.c
index edd6930..a3d1c10 100644
--- a/dlls/urlmon/urlmon_main.c
+++ b/dlls/urlmon/urlmon_main.c
@@ -566,13 +566,19 @@ static BOOL text_html_filter(const BYTE *b, DWORD size)
     if(size < 5)
         return FALSE;
 
-    for(i=0; i < size-5; i++) {
-        if(b[i] == '<'
-           && (b[i+1] == 'h' || b[i+1] == 'H')
-           && (b[i+2] == 't' || b[i+2] == 'T')
-           && (b[i+3] == 'm' || b[i+3] == 'M')
-           && (b[i+4] == 'l' || b[i+4] == 'L'))
-            return TRUE;
+    for(i = 0; i < size-5; i++) {
+        if((b[i] == '<'
+            && (b[i+1] == 'h' || b[i+1] == 'H')
+            && (b[i+2] == 't' || b[i+2] == 'T')
+            && (b[i+3] == 'm' || b[i+3] == 'M')
+            && (b[i+4] == 'l' || b[i+4] == 'L')) ||
+           ((size - i >= 6)
+            &&  b[i]   == '<'
+            && (b[i+1] == 'h' || b[i+1] == 'H')
+            && (b[i+2] == 'e' || b[i+2] == 'E')
+            && (b[i+3] == 'a' || b[i+3] == 'A')
+            && (b[i+4] == 'd' || b[i+4] == 'D')
+            &&  b[i+5] == '>')) return TRUE;
     }
 
     return FALSE;
-- 
1.5.6.5

