aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cow_link.erl16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/cow_link.erl b/src/cow_link.erl
index 4cf24c2..3a9526c 100644
--- a/src/cow_link.erl
+++ b/src/cow_link.erl
@@ -363,10 +363,15 @@ do_link(#{target := TargetURI, rel := Rel, attributes := Params}) ->
[
$<, TargetURI, <<">"
"; rel=\"">>, Rel, $",
- [[<<"; ">>, Key, <<"=\"">>, Value, $"]
+ [[<<"; ">>, Key, <<"=\"">>, escape(Value, <<>>), $"]
|| {Key, Value} <- Params]
].
+escape(<<>>, Acc) -> Acc;
+escape(<<$\\,R/bits>>, Acc) -> escape(R, <<Acc/binary,$\\,$\\>>);
+escape(<<$\",R/bits>>, Acc) -> escape(R, <<Acc/binary,$\\,$\">>);
+escape(<<C,R/bits>>, Acc) -> escape(R, <<Acc/binary,C>>).
+
-ifdef(TEST).
link_test_() ->
Tests = [
@@ -420,6 +425,15 @@ link_test_() ->
rel => <<"index">>,
attributes => []
}
+ ]},
+ {<<"</>; rel=\"previous\"; quoted=\"name=\\\"value\\\"\"">>, [
+ #{
+ target => <<"/">>,
+ rel => <<"previous">>,
+ attributes => [
+ {<<"quoted">>, <<"name=\"value\"">>}
+ ]
+ }
]}
],
[{iolist_to_binary(io_lib:format("~0p", [V])),