aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/stdlib/doc/src/uri_string.xml10
-rw-r--r--lib/stdlib/src/uri_string.erl4
-rw-r--r--lib/stdlib/test/uri_string_SUITE.erl6
3 files changed, 13 insertions, 7 deletions
diff --git a/lib/stdlib/doc/src/uri_string.xml b/lib/stdlib/doc/src/uri_string.xml
index 496573ae2f..97b38ea93e 100644
--- a/lib/stdlib/doc/src/uri_string.xml
+++ b/lib/stdlib/doc/src/uri_string.xml
@@ -28,9 +28,10 @@
<rev>A</rev>
</header>
<module>uri_string</module>
- <modulesummary>RFC 3986 compliant URI processing functions.</modulesummary>
+ <modulesummary>URI processing functions.</modulesummary>
<description>
- <p>This module contains functions for parsing and handling RFC 3986 compliant URIs.</p>
+ <p>This module contains functions for parsing and handling URIs (RFC 3986) and
+ form-urlencoded query strings (RFC 1866).</p>
<p>A URI is an identifier consisting of a sequence of characters matching the syntax
rule named <em>URI</em> in <em>RFC 3986</em>.</p>
<p> The generic URI syntax consists of a hierarchical sequence of components referred
@@ -109,7 +110,7 @@
<c><anno>QueryList</anno></c>, a list of unescaped key-value pairs.
Media type <c>application/x-www-form-urlencoded</c> is defined in section
8.2.1 of <c>RFC 1866</c> (HTML 2.0). Reserved and unsafe characters, as
- defined by RFC 1738 (Uniform Resource Locators), are procent-encoded.
+ defined by RFC 1738 (Uniform Resource Locators), are percent-encoded.
</p>
<p><em>Example:</em></p>
<pre>
@@ -125,8 +126,7 @@
<desc>
<p>Same as <c>compose_query/1</c> but with an additional
<c><anno>Options</anno></c> parameter, that controls the type of separator used
- between key-value pairs. There are two supported separator types: <c>amp</c> (<![CDATA[&amp;]]>)
- and <c>semicolon</c> (;).</p>
+ between key-value pairs. There are three supported separator types: <c>amp</c> (<![CDATA[&]]>), <c>escaped_amp</c> (<![CDATA[&amp;]]>) and <c>semicolon</c> (;). If the parameter <c><anno>Options</anno></c> is empty, separator takes the default value (<c>escaped_amp</c>).</p>
<p><em>Example:</em></p>
<pre>
1> <input>uri_string:compose_query([{"foo bar","1"},{"city","örebro"}],</input>
diff --git a/lib/stdlib/src/uri_string.erl b/lib/stdlib/src/uri_string.erl
index 8723d3f183..a4fd9c66f4 100644
--- a/lib/stdlib/src/uri_string.erl
+++ b/lib/stdlib/src/uri_string.erl
@@ -1806,6 +1806,8 @@ get_separator(_, Acc) when length(Acc) =:= 0 ->
get_separator([], _Acc) ->
"&amp;";
get_separator([{separator, amp}], _Acc) ->
+ "&";
+get_separator([{separator, escaped_amp}], _Acc) ->
"&amp;";
get_separator([{separator, semicolon}], _Acc) ->
";".
@@ -1901,6 +1903,8 @@ dissect_query_value([], Acc, Key, Value) ->
dissect_query_separator_amp("&amp;" ++ T, Acc, Key, Value) ->
dissect_query_key(T, Acc, Key, Value);
+dissect_query_separator_amp("&" ++ T, Acc, Key, Value) ->
+ dissect_query_key(T, Acc, Key, Value);
dissect_query_separator_amp(L, _, _, _) ->
throw({error, invalid_separator, L}).
diff --git a/lib/stdlib/test/uri_string_SUITE.erl b/lib/stdlib/test/uri_string_SUITE.erl
index b70cb842de..fe832ac82c 100644
--- a/lib/stdlib/test/uri_string_SUITE.erl
+++ b/lib/stdlib/test/uri_string_SUITE.erl
@@ -827,7 +827,8 @@ transcode_negative(_Config) ->
compose_query(_Config) ->
[] = uri_string:compose_query([]),
"foo=1&amp;bar=2" = uri_string:compose_query([{<<"foo">>,"1"}, {"bar", "2"}]),
- "foo=1&amp;bar=2" = uri_string:compose_query([{"foo","1"}, {"bar", "2"}],[{separator,amp}]),
+ "foo=1&amp;bar=2" = uri_string:compose_query([{"foo","1"}, {"bar", "2"}],[{separator,escaped_amp}]),
+ "foo=1&bar=2" = uri_string:compose_query([{"foo","1"}, {"bar", "2"}],[{separator,amp}]),
"foo=1;bar=2" = uri_string:compose_query([{"foo","1"}, {"bar", "2"}],[{separator,semicolon}]),
"foo+bar=1&amp;%C3%B6=2" = uri_string:compose_query([{"foo bar","1"}, {"ö", "2"}]).
@@ -837,12 +838,13 @@ compose_query_negative(_Config) ->
dissect_query(_Config) ->
[] = uri_string:dissect_query(""),
[{"foo","1"}, {"bar", "2"}] = uri_string:dissect_query("foo=1&amp;bar=2"),
+ [{"foo","1"}, {"bar", "2"}] = uri_string:dissect_query("foo=1&bar=2"),
[{"foo","1"}, {"bar", "2"}] = uri_string:dissect_query("foo=1;bar=2"),
[{"foo","1"}, {"bar", "222"}] = uri_string:dissect_query([<<"foo=1;bar=2">>,"22"]),
[{"foo","ö"}, {"bar", "2"}] = uri_string:dissect_query("foo=%C3%B6&amp;bar=2").
dissect_query_negative(_Config) ->
- {error,invalid_separator,"&ap;bar=2"} =
+ {error,urldecode,";bar"} =
uri_string:dissect_query("foo=1&ap;bar=2"),
{error,urldecode,"&amp;bar"} =
uri_string:dissect_query("foo1&amp;bar=2"),