diff --git a/src/Text/Blaze/Renderer/Utf8.hs b/src/Text/Blaze/Renderer/Utf8.hs index 0e4018d..b37b680 100644 --- a/src/Text/Blaze/Renderer/Utf8.hs +++ b/src/Text/Blaze/Renderer/Utf8.hs @@ -49,9 +49,10 @@ renderBuilder = go mempty `mappend` attrs `mappend` B.copyByteString (getUtf8ByteString end) go attrs (AddAttribute key value h) = - go (attrs `mappend` B.copyByteString (getUtf8ByteString key) + go (B.copyByteString (getUtf8ByteString key) `mappend` fromChoiceString value - `mappend` B.fromChar '"') h + `mappend` B.fromChar '"' + `mappend` attrs) h go _ (Content content) = fromChoiceString content go attrs (Append h1 h2) = go attrs h1 `mappend` go attrs h2 go _ (Empty _) = mempty diff --git a/tests/Text/Blaze/Tests.hs b/tests/Text/Blaze/Tests.hs index 819b297..59caa9e 100644 --- a/tests/Text/Blaze/Tests.hs +++ b/tests/Text/Blaze/Tests.hs @@ -20,6 +20,7 @@ import Test.Framework.Providers.HUnit import Test.HUnit hiding (Test) import Text.Blaze.Html5 hiding (map) +import qualified Text.Blaze.Html5 as H import Text.Blaze.Html5.Attributes import Text.Blaze.Renderer.Utf8 (renderHtml) @@ -31,6 +32,8 @@ tests = [ testProperty "left identity Monoid law" monoidLeftIdentity , testCase "escaping case 1" escaping1 , testCase "escaping case 2" escaping2 , testProperty "post escaping characters" postEscapingCharacters + , testCase "template case 1" template1 + , testCase "template case 2" template2 ] -- | The left identity Monoid law. @@ -71,6 +74,24 @@ postEscapingCharacters str = where forbidden = map (fromIntegral . ord) "\"'<>" +-- | Simple template test case +-- +template1 :: Assertion +template1 = expected @=? renderHtml template + where + expected = "

banana

banana
" + template = div ! id "foo" $ do + p "banana" + H.span "banana" + +-- | Simple template test case +-- +template2 :: Assertion +template2 = expected @=? renderHtml template + where + expected = "\"bar\"" + template = img ! src "foo.png" ! alt "bar" + -- Show instance for the HTML type, so we can debug. -- instance Show Html where