Skip to content

Commit

Permalink
Always apply jsAttributes to scritps in body (#1836)
Browse files Browse the repository at this point in the history
* breadcrumb test should be in cabal

* failing test for jsAttributes

* also apply jsAttributes to scripts without a location
the location is only set if cached by addStaticContent

* bump version number

* add changelog
  • Loading branch information
dten authored Jul 15, 2024
1 parent bcfcd94 commit 10f218a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
4 changes: 4 additions & 0 deletions yesod-core/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog for yesod-core

## 1.6.26.0

* Always apply jsAttributes to julius script blocks of body [#1836](https://github.com/yesodweb/yesod/pull/1836)

## 1.6.25.1

* Export the options that were created in 1.6.25.0 [#1825](https://github.com/yesodweb/yesod/pull/1825)
Expand Down
2 changes: 1 addition & 1 deletion yesod-core/src/Yesod/Core/Class/Yesod.hs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ widgetToPageContent w = do
$maybe s <- jsLoc
<script src="#{s}" *{jsAttrs}>
$nothing
<script>^{jelper j}
<script *{jsAttrs}>^{jelper j}
|]

headAll = [hamlet|
Expand Down
2 changes: 2 additions & 0 deletions yesod-core/test/YesodCoreTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import YesodCoreTest.ParameterizedSite
import YesodCoreTest.Breadcrumb
import qualified YesodCoreTest.WaiSubsite as WaiSubsite
import qualified YesodCoreTest.Redirect as Redirect
import qualified YesodCoreTest.JsAttributes as JsAttributes
import qualified YesodCoreTest.JsLoader as JsLoader
import qualified YesodCoreTest.RequestBodySize as RequestBodySize
import qualified YesodCoreTest.Json as Json
Expand Down Expand Up @@ -51,6 +52,7 @@ specs = do
parameterizedSiteTest
WaiSubsite.specs
Redirect.specs
JsAttributes.specs
JsLoader.specs
RequestBodySize.specs
Json.specs
Expand Down
37 changes: 37 additions & 0 deletions yesod-core/test/YesodCoreTest/JsAttributes.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{-# LANGUAGE QuasiQuotes, TypeFamilies, TemplateHaskell, MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}
module YesodCoreTest.JsAttributes
( specs
-- To avoid unused warning
, Widget
, resourcesApp
) where

import Test.Hspec

import Yesod.Core
import Network.Wai.Test

data App = App
mkYesod "App" [parseRoutes|
/ HeadR GET
|]
instance Yesod App where
jsAttributes _ = [("attr0", "a")]

getHeadR :: Handler Html
getHeadR = defaultLayout $ do
addScriptRemote "load.js"
toWidget [julius|/*body*/|]
toWidgetHead [julius|/*head*/|]

specs :: Spec
specs = describe "Test.JsAttributes" $ do
it "script in body gets attributes" $ runner App $ do
res <- request defaultRequest
assertBody "<!DOCTYPE html>\n<html><head><title></title><script>/*head*/</script></head><body><script src=\"load.js\"></script><script attr0=\"a\">/*body*/</script></body></html>" res

runner :: YesodDispatch master => master -> Session () -> IO ()
runner app f = toWaiApp app >>= runSession f

4 changes: 3 additions & 1 deletion yesod-core/yesod-core.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: yesod-core
version: 1.6.25.1
version: 1.6.26.0
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
Expand Down Expand Up @@ -142,6 +142,7 @@ test-suite tests

other-modules: YesodCoreTest
YesodCoreTest.Auth
YesodCoreTest.Breadcrumb
YesodCoreTest.Cache
YesodCoreTest.CleanPath
YesodCoreTest.Header
Expand All @@ -150,6 +151,7 @@ test-suite tests
YesodCoreTest.ErrorHandling.CustomApp
YesodCoreTest.Exceptions
YesodCoreTest.InternalRequest
YesodCoreTest.JsAttributes
YesodCoreTest.JsLoader
YesodCoreTest.JsLoaderSites.Bottom
YesodCoreTest.Json
Expand Down

0 comments on commit 10f218a

Please sign in to comment.