|
@@ -37,37 +37,6 @@ coalesce([undefined|T]) -> coalesce(T);
|
|
|
coalesce([[]|T]) -> coalesce(T);
|
|
|
coalesce([H|_]) -> H.
|
|
|
|
|
|
-hte(X) when erlang:is_binary(X) ->
|
|
|
- nitro:to_binary(nitro_conv:html_encode(X));
|
|
|
-hte(X) -> nitro_conv:html_encode(X).
|
|
|
-
|
|
|
-
|
|
|
-%% JavaScript encode/decode
|
|
|
-
|
|
|
-js_escape(undefined) -> [];
|
|
|
-js_escape(Value) when erlang:is_list(Value) ->
|
|
|
- erlang:binary_to_list(js_escape(erlang:iolist_to_binary(Value)));
|
|
|
-js_escape(Value) -> js_escape(Value, <<>>).
|
|
|
-
|
|
|
-js_escape(<<"\\", Rest/binary>>, Acc) -> %"
|
|
|
- js_escape(Rest, <<Acc/binary, "\\\\">>); %"
|
|
|
-js_escape(<<"\r", Rest/binary>>, Acc) ->
|
|
|
- js_escape(Rest, <<Acc/binary, "\\r">>);
|
|
|
-js_escape(<<"\n", Rest/binary>>, Acc) ->
|
|
|
- js_escape(Rest, <<Acc/binary, "\\n">>);
|
|
|
-js_escape(<<"\"", Rest/binary>>, Acc) ->
|
|
|
- js_escape(Rest, <<Acc/binary, "\\\"">>);
|
|
|
-js_escape(<<"'", Rest/binary>>, Acc) ->
|
|
|
- js_escape(Rest, <<Acc/binary, "\\'">>);
|
|
|
-js_escape(<<"`", Rest/binary>>, Acc) ->
|
|
|
- js_escape(Rest, <<Acc/binary, "\\`">>);
|
|
|
-js_escape(<<"<script", Rest/binary>>, Acc) ->
|
|
|
- js_escape(Rest, <<Acc/binary, "<script">>);
|
|
|
-js_escape(<<"script>", Rest/binary>>, Acc) ->
|
|
|
- js_escape(Rest, <<Acc/binary, "script>">>);
|
|
|
-js_escape(<<C, Rest/binary>>, Acc) ->
|
|
|
- js_escape(Rest, <<Acc/binary, C>>);
|
|
|
-js_escape(<<>>, Acc) -> Acc.
|
|
|
|
|
|
|
|
|
-define(IS_STRING(Term),
|
|
@@ -126,6 +95,34 @@ temp_id() ->
|
|
|
"auto" ++ integer_to_list(unique_integer() rem 1000000).
|
|
|
|
|
|
|
|
|
+%% JavaScript encode/decode
|
|
|
+
|
|
|
+js_escape(undefined) -> [];
|
|
|
+js_escape(Value) when erlang:is_list(Value) ->
|
|
|
+ erlang:binary_to_list(js_escape(erlang:iolist_to_binary(Value)));
|
|
|
+js_escape(Value) -> js_escape(Value, <<>>).
|
|
|
+
|
|
|
+js_escape(<<"\\", Rest/binary>>, Acc) -> %"
|
|
|
+ js_escape(Rest, <<Acc/binary, "\\\\">>); %"
|
|
|
+js_escape(<<"\r", Rest/binary>>, Acc) ->
|
|
|
+ js_escape(Rest, <<Acc/binary, "\\r">>);
|
|
|
+js_escape(<<"\n", Rest/binary>>, Acc) ->
|
|
|
+ js_escape(Rest, <<Acc/binary, "\\n">>);
|
|
|
+js_escape(<<"\"", Rest/binary>>, Acc) ->
|
|
|
+ js_escape(Rest, <<Acc/binary, "\\\"">>);
|
|
|
+js_escape(<<"'", Rest/binary>>, Acc) ->
|
|
|
+ js_escape(Rest, <<Acc/binary, "\\'">>);
|
|
|
+js_escape(<<"`", Rest/binary>>, Acc) ->
|
|
|
+ js_escape(Rest, <<Acc/binary, "\\`">>);
|
|
|
+js_escape(<<"<script", Rest/binary>>, Acc) ->
|
|
|
+ js_escape(Rest, <<Acc/binary, "<script">>);
|
|
|
+js_escape(<<"script>", Rest/binary>>, Acc) ->
|
|
|
+ js_escape(Rest, <<Acc/binary, "script>">>);
|
|
|
+js_escape(<<C, Rest/binary>>, Acc) ->
|
|
|
+ js_escape(Rest, <<Acc/binary, C>>);
|
|
|
+js_escape(<<>>, Acc) -> Acc.
|
|
|
+
|
|
|
+
|
|
|
% HTML encode/decode
|
|
|
|
|
|
%% html_encode(B, normal)
|
|
@@ -150,7 +147,9 @@ html_encode(<<>>) ->
|
|
|
html_encode([]) ->
|
|
|
[];
|
|
|
html_encode(B) when is_binary(B) ->
|
|
|
- html_encode(erlang:binary_to_list(B));
|
|
|
+ nitro:to_binary(
|
|
|
+ html_encode(erlang:binary_to_list(B))
|
|
|
+ );
|
|
|
html_encode([$\n |T]) ->
|
|
|
"<br>" ++ html_encode(T);
|
|
|
html_encode([H|T]) ->
|