Commit f011f7d1 authored by Steffen Michels's avatar Steffen Michels

Merge branch 'fix-stack-overflow-in-Text.HTML' into 'master'

Remove recursion from escaping functions in Text.HTML

See merge request !339
parents d58cd793 6dbfe2b6
Pipeline #43487 passed with stage
in 2 minutes and 18 seconds
......@@ -255,31 +255,31 @@ attrsSize attrs = intsum attrSize attrs
// Calculates the number of chars in a string when html special characters are escaped
// This version is for text nodes: <, >, and & are escaped
escapedSize :: !{#Char} -> Int
escapedSize s = escapedSize` s (size s) 0
escapedSize s = escapedSize` s (size s) 0 0
where
escapedSize` :: !{#Char} !Int !Int -> Int
escapedSize` s n i
| i == n = 0
| s.[i] == '<' = 4 + escapedSize` s n (i + 1)
| s.[i] == '>' = 4 + escapedSize` s n (i + 1)
| s.[i] == '&' = 5 + escapedSize` s n (i + 1)
| otherwise = 1 + escapedSize` s n (i + 1)
escapedSize` :: !{#Char} !Int !Int !Int -> Int
escapedSize` s n i sz
| i == n = sz
| s.[i] == '<' = escapedSize` s n (i + 1) (sz + 4)
| s.[i] == '>' = escapedSize` s n (i + 1) (sz + 4)
| s.[i] == '&' = escapedSize` s n (i + 1) (sz + 5)
| otherwise = escapedSize` s n (i + 1) (sz + 1)
// Calculates the number of chars in a string when html special characters are escaped
// This version is for attribute values: " and & are escaped
escapedAttrSize :: !{#Char} -> Int
escapedAttrSize s = escapedSize` s (size s) 0
escapedAttrSize s = escapedSize` s (size s) 0 0
where
escapedSize` :: !{#Char} !Int !Int -> Int
escapedSize` s n i
| i == n = 0
escapedSize` :: !{#Char} !Int !Int !Int -> Int
escapedSize` s n i sz
| i == n = sz
| s.[i] == '<' || s.[i] == '>' // NB: these are accepted by HTML, but not by XML
= 4 + escapedSize` s n (i + 1)
= escapedSize` s n (i + 1) (sz + 4)
| s.[i] == '"'
= 6 + escapedSize` s n (i + 1)
= escapedSize` s n (i + 1) (sz + 6)
| s.[i] == '&'
= 5 + escapedSize` s n (i + 1)
= 1 + escapedSize` s n (i + 1)
= escapedSize` s n (i + 1) (sz + 5)
= escapedSize` s n (i + 1) (sz + 1)
serializeTag :: !HtmlTag !*{#Char} !Int -> (!*{#Char}, !Int)
serializeTag (Text t) s i = copyChars t 0 True s i
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment