aboutsummaryrefslogtreecommitdiffstats
path: root/src/cow_http.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-06-06 15:26:58 +0200
committerLoïc Hoguin <[email protected]>2016-06-06 15:26:58 +0200
commit92d75b5e90d837a263f03986ba2657b7fa0a6954 (patch)
treec201245fd70432b2ee3d26c1dc1c0aa74f65b014 /src/cow_http.erl
parentfaf4795d0c2adc3951a023bdbc8943f4373b54d8 (diff)
downloadcowlib-92d75b5e90d837a263f03986ba2657b7fa0a6954.tar.gz
cowlib-92d75b5e90d837a263f03986ba2657b7fa0a6954.tar.bz2
cowlib-92d75b5e90d837a263f03986ba2657b7fa0a6954.zip
Make cow_http:parse_fullpath/1 remove any fragment component
Diffstat (limited to 'src/cow_http.erl')
-rw-r--r--src/cow_http.erl20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/cow_http.erl b/src/cow_http.erl
index 4b98d81..c76675c 100644
--- a/src/cow_http.erl
+++ b/src/cow_http.erl
@@ -196,25 +196,31 @@ horse_parse_headers() ->
).
-endif.
-%% @doc Extract path and query string from a binary.
+%% @doc Extract path and query string from a binary,
+%% removing any fragment component.
-spec parse_fullpath(binary()) -> {binary(), binary()}.
parse_fullpath(Fullpath) ->
parse_fullpath(Fullpath, <<>>).
-parse_fullpath(<<>>, Path) ->
- {Path, <<>>};
-parse_fullpath(<< $?, Qs/binary >>, Path) ->
- {Path, Qs};
-parse_fullpath(<< C, Rest/binary >>, SoFar) ->
- parse_fullpath(Rest, << SoFar/binary, C >>).
+parse_fullpath(<<>>, Path) -> {Path, <<>>};
+parse_fullpath(<< $#, _/bits >>, Path) -> {Path, <<>>};
+parse_fullpath(<< $?, Qs/bits >>, Path) -> parse_fullpath_query(Qs, Path, <<>>);
+parse_fullpath(<< C, Rest/bits >>, SoFar) -> parse_fullpath(Rest, << SoFar/binary, C >>).
+
+parse_fullpath_query(<<>>, Path, Query) -> {Path, Query};
+parse_fullpath_query(<< $#, _/bits >>, Path, Query) -> {Path, Query};
+parse_fullpath_query(<< C, Rest/bits >>, Path, SoFar) ->
+ parse_fullpath_query(Rest, Path, << SoFar/binary, C >>).
-ifdef(TEST).
parse_fullpath_test() ->
{<<"*">>, <<>>} = parse_fullpath(<<"*">>),
{<<"/">>, <<>>} = parse_fullpath(<<"/">>),
+ {<<"/path/to/resource">>, <<>>} = parse_fullpath(<<"/path/to/resource#fragment">>),
{<<"/path/to/resource">>, <<>>} = parse_fullpath(<<"/path/to/resource">>),
{<<"/">>, <<>>} = parse_fullpath(<<"/?">>),
+ {<<"/">>, <<"q=cowboy">>} = parse_fullpath(<<"/?q=cowboy#fragment">>),
{<<"/">>, <<"q=cowboy">>} = parse_fullpath(<<"/?q=cowboy">>),
{<<"/path/to/resource">>, <<"q=cowboy">>}
= parse_fullpath(<<"/path/to/resource?q=cowboy">>),