diff --git a/src/Text/XmlHtml/HTML/Parse.hs b/src/Text/XmlHtml/HTML/Parse.hs
--- a/src/Text/XmlHtml/HTML/Parse.hs
+++ b/src/Text/XmlHtml/HTML/Parse.hs
@@ -252,10 +252,10 @@
 endTag s = do
     _ <- text "</"
     t <- XML.name
-    let tbase = T.toLower $ snd $ T.breakOnEnd ":" t
+    let sbase = T.toLower $ snd $ T.breakOnEnd ":" s
     r <- if (T.toCaseFold s == T.toCaseFold t)
             then return Matched
-            else if tbase `S.member` endOmittableLast
+            else if sbase `S.member` endOmittableLast
                 then return (ImplicitLast t)
                 else fail $ "mismatched tags: </" ++ T.unpack t ++
                             "> found inside <" ++ T.unpack s ++ "> tag"
diff --git a/test/suite/Text/XmlHtml/Tests.hs b/test/suite/Text/XmlHtml/Tests.hs
--- a/test/suite/Text/XmlHtml/Tests.hs
+++ b/test/suite/Text/XmlHtml/Tests.hs
@@ -383,7 +383,9 @@
     testIt   "omitEndTR              " omitEndTR,
     testIt   "omitEndTD              " omitEndTD,
     testIt   "omitEndTH              " omitEndTH,
-    testIt   "testNewRefs            " testNewRefs
+    testIt   "testNewRefs            " testNewRefs,
+    testIt   "errorImplicitClose     " errorImplicitClose,
+    testIt   "weirdScriptThing       " weirdScriptThing
     ]
 
 caseInsDoctype1 :: Bool
@@ -522,6 +524,18 @@
 testNewRefs   = parseHTML "" "&CenterDot;&doublebarwedge;&fjlig;"
     == Right (HtmlDocument UTF8 Nothing [TextNode "\x000B7\x02306\&fj"])
 
+errorImplicitClose :: Bool
+errorImplicitClose = isLeft $ parseHTML "" "<p><pre>foo</pre></p>"
+
+weirdScriptThing :: Bool
+weirdScriptThing = parseHTML "" "<div><script type=\"text/javascript\">selector.append('<option>'+name+'</option>');</script></div>"
+    == Right (HtmlDocument UTF8 Nothing [
+        Element "div" [] [
+            Element "script" [("type", "text/javascript")] [
+                TextNode "selector.append('<option>'+name+'</option>');"
+                ]
+            ]
+        ])
 
 ------------------------------------------------------------------------------
 -- XML Rendering Tests -------------------------------------------------------
diff --git a/xmlhtml.cabal b/xmlhtml.cabal
--- a/xmlhtml.cabal
+++ b/xmlhtml.cabal
@@ -1,5 +1,5 @@
 Name:                xmlhtml
-Version:             0.1.5.1
+Version:             0.1.5.2
 Synopsis:            XML parser and renderer with HTML 5 quirks mode
 Description:         Contains renderers and parsers for both XML and HTML 5
                      document fragments, which share data structures wo that
