diff --git a/web/making_a_web_site.anubis b/web/making_a_web_site.anubis index bb663c6..e34f02f 100644 --- a/web/making_a_web_site.anubis +++ b/web/making_a_web_site.anubis @@ -120,6 +120,50 @@ public define String _HTML_encode_entities(explode(source), []) . +define List(Word8) +/** Test for HTML entity which must be encoded + * and return the encoded entity if needed + */ + get_entity_quote + ( + Word8 _char, + List(Word8) tail + )= + //test for the ampersand + if _char = '&' then + //test if it's already an encoded string like & < etc. In that case we do nothing + if insensitive_equal(['&','a','m','p',';'], tail, 0) then [_char] + else if insensitive_equal(['&','l','t',';'], tail, 0) then [_char] + else if insensitive_equal(['&','g','t',';'], tail, 0) then [_char] + else if insensitive_equal(['&','q','u','o','t',';'], tail, 0) then [_char] + else + [';','p','m','a','&'] + //test for '"' only. + else if _char = '\"' then [';','t','o','u','q','&'] + else [_char] +. + +define String + _HTML_encode_quote + ( + List(Word8) source, + List(Word8) current + )= + if source is + { + [] then implode(reverse(current)), + [c . t] then + _HTML_encode_quote(t, get_entity_quote(c, t) + current) + } +. + +public define String + encode_HTML_quote + ( + String source + )= + _HTML_encode_quote(explode(source), []) +. * (1) Structure of a web site. @@ -1562,6 +1606,7 @@ public define HTML_Off_Form label(List(CoreAttrs) attrs, String string) //