elm-pages 3.0.21 → 3.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  - [elm-pages Docs Site](https://elm-pages.com/docs)
13
13
  - [elm-pages site showcase](https://elm-pages.com/showcase/)
14
- - [elm-pages Elm API Docs](https://package.elm-lang.org/packages/dillonkearns/elm-pages/10.2.0/)
14
+ - [elm-pages Elm API Docs](https://package.elm-lang.org/packages/dillonkearns/elm-pages/10.2.1/)
15
15
  - [Quick start repo](https://github.com/dillonkearns/elm-pages-starter) [(live site hosted here)](https://elm-pages-starter.netlify.com)
16
16
  - [Introducing `elm-pages` blog post](https://elm-pages.com/blog/introducing-elm-pages)
17
17
  - [`examples` folder](https://github.com/dillonkearns/elm-pages/blob/master/examples/) (includes https://elm-pages.com site source) Use `git clone --recurse-submodules https://github.com/dillonkearns/elm-pages.git` so that there aren't missing files when you try to build the examples.
@@ -1,3 +1,3 @@
1
1
  export const compatibilityKey = 22;
2
2
 
3
- export const packageVersion = "3.0.21";
3
+ export const packageVersion = "3.0.22";
@@ -14,7 +14,7 @@
14
14
  "dillonkearns/elm-bcp47-language-tag": "2.0.0",
15
15
  "dillonkearns/elm-form": "3.0.1",
16
16
  "dillonkearns/elm-markdown": "7.0.1",
17
- "dillonkearns/elm-pages": "10.2.0",
17
+ "dillonkearns/elm-pages": "10.2.1",
18
18
  "elm/browser": "1.0.2",
19
19
  "elm/bytes": "1.0.8",
20
20
  "elm/core": "1.0.5",
@@ -9,7 +9,7 @@
9
9
  "devDependencies": {
10
10
  "elm-codegen": "^0.6.1",
11
11
  "elm-optimize-level-2": "^0.3.5",
12
- "elm-pages": "3.0.21",
12
+ "elm-pages": "3.0.22",
13
13
  "elm-review": "^2.12.0",
14
14
  "elm-tooling": "^1.15.1",
15
15
  "lamdera": "^0.19.1-1.3.2",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "elm-pages",
3
3
  "type": "module",
4
- "version": "3.0.21",
4
+ "version": "3.0.22",
5
5
  "homepage": "https://elm-pages.com",
6
6
  "moduleResolution": "node",
7
7
  "description": "Hybrid Elm framework with full-stack and static routes.",
@@ -2,7 +2,7 @@ module Test.Html.Internal.ElmHtml.InternalTypes exposing
2
2
  ( ElmHtml(..), TextTagRecord, NodeRecord, CustomNodeRecord, MarkdownNodeRecord
3
3
  , Facts, Tagger, EventHandler, ElementKind(..)
4
4
  , Attribute(..), AttributeRecord, NamespacedAttributeRecord, PropertyRecord, EventRecord
5
- , decodeElmHtml, emptyFacts, toElementKind, decodeAttribute
5
+ , decodeElmHtml, emptyFacts, toElementKind, decodeAttribute, isUnsafeName
6
6
  )
7
7
 
8
8
  {-| Internal types used to represent Elm Html in pure Elm
@@ -13,7 +13,7 @@ module Test.Html.Internal.ElmHtml.InternalTypes exposing
13
13
 
14
14
  @docs Attribute, AttributeRecord, NamespacedAttributeRecord, PropertyRecord, EventRecord
15
15
 
16
- @docs decodeElmHtml, emptyFacts, toElementKind, decodeAttribute
16
+ @docs decodeElmHtml, emptyFacts, toElementKind, decodeAttribute, isUnsafeName
17
17
 
18
18
  -}
19
19
 
@@ -21,6 +21,7 @@ import Dict exposing (Dict)
21
21
  import Html.Events
22
22
  import Json.Decode exposing (field)
23
23
  import Json.Encode
24
+ import Regex exposing (Regex)
24
25
  import Test.Html.Internal.ElmHtml.Constants as Constants exposing (..)
25
26
  import Test.Html.Internal.ElmHtml.Helpers exposing (..)
26
27
  import Test.Html.Internal.ElmHtml.Markdown exposing (..)
@@ -124,6 +125,7 @@ type ElementKind
124
125
  | EscapableRawTextElements
125
126
  | ForeignElements
126
127
  | NormalElements
128
+ | InvalidElements
127
129
 
128
130
 
129
131
  type HtmlContext msg
@@ -510,12 +512,27 @@ escapableRawTextElements =
510
512
  -}
511
513
 
512
514
 
515
+ unsafeName : Regex
516
+ unsafeName =
517
+ {- https://github.com/preactjs/preact-render-to-string/blob/27f340b6e7d77ec7775a49a78d105cad26fa0857/src/lib/util.js#L2 -}
518
+ Regex.fromString "[\\s\\n\\\\/='\"\\0<>]"
519
+ |> Maybe.withDefault Regex.never
520
+
521
+
522
+ isUnsafeName : String -> Bool
523
+ isUnsafeName name =
524
+ Regex.contains unsafeName name
525
+
526
+
513
527
  {-| Identify the kind of element. Helper to convert an tag name into a type for
514
528
  pattern matching.
515
529
  -}
516
530
  toElementKind : String -> ElementKind
517
531
  toElementKind element =
518
- if List.member element voidElements then
532
+ if isUnsafeName element then
533
+ InvalidElements
534
+
535
+ else if List.member element voidElements then
519
536
  VoidElements
520
537
 
521
538
  else if List.member element rawTextElements then
@@ -115,23 +115,25 @@ nodeRecordToString options { tag, children, facts } =
115
115
  styleValues
116
116
  |> List.map (\( key, value ) -> key ++ ":" ++ value ++ ";")
117
117
  |> String.join ""
118
- |> (\styleString -> "style=\"" ++ styleString ++ "\"")
118
+ |> (\styleString -> "style=\"" ++ escapeHtml styleString ++ "\"")
119
119
  |> Just
120
120
 
121
121
  classes =
122
122
  Dict.get "className" facts.stringAttributes
123
- |> Maybe.map (\name -> "class=\"" ++ name ++ "\"")
123
+ |> Maybe.map (\name -> "class=\"" ++ escapeHtml name ++ "\"")
124
124
 
125
125
  stringAttributes =
126
126
  Dict.filter (\k v -> k /= "className") facts.stringAttributes
127
127
  |> Dict.toList
128
+ |> List.filter (\( k, _ ) -> not (isUnsafeName k))
128
129
  |> List.map (Tuple.mapFirst propertyToAttributeName)
129
- |> List.map (\( k, v ) -> k ++ "=\"" ++ v ++ "\"")
130
+ |> List.map (\( k, v ) -> k ++ "=\"" ++ escapeHtml v ++ "\"")
130
131
  |> String.join " "
131
132
  |> Just
132
133
 
133
134
  boolAttributes =
134
135
  Dict.toList facts.boolAttributes
136
+ |> List.filter (\( k, _ ) -> not (isUnsafeName k))
135
137
  |> List.filterMap
136
138
  (\( k, v ) ->
137
139
  if v then
@@ -144,6 +146,9 @@ nodeRecordToString options { tag, children, facts } =
144
146
  |> Just
145
147
  in
146
148
  case toElementKind tag of
149
+ InvalidElements ->
150
+ [ "<!-- invalid element -->" ]
151
+
147
152
  {- Void elements only have a start tag; end tags must not be
148
153
  specified for void elements.
149
154
  -}
@@ -187,10 +192,15 @@ escapeRawText kind rawText =
187
192
  rawText
188
193
 
189
194
  _ ->
190
- {- https://github.com/elm/virtual-dom/blob/5a5bcf48720bc7d53461b3cd42a9f19f119c5503/src/Elm/Kernel/VirtualDom.server.js#L8-L26 -}
191
- rawText
192
- |> String.replace "&" "&amp;"
193
- |> String.replace "<" "&lt;"
194
- |> String.replace ">" "&gt;"
195
- |> String.replace "\"" "&quot;"
196
- |> String.replace "'" "&#039;"
195
+ escapeHtml rawText
196
+
197
+
198
+ escapeHtml : String -> String
199
+ escapeHtml rawText =
200
+ {- https://github.com/elm/virtual-dom/blob/5a5bcf48720bc7d53461b3cd42a9f19f119c5503/src/Elm/Kernel/VirtualDom.server.js#L8-L26 -}
201
+ rawText
202
+ |> String.replace "&" "&amp;"
203
+ |> String.replace "<" "&lt;"
204
+ |> String.replace ">" "&gt;"
205
+ |> String.replace "\"" "&quot;"
206
+ |> String.replace "'" "&#039;"