Skip to content

Commit 17c4c4d

Browse files
author
José Valim
committed
Do more strict matching on URI scheme
Signed-off-by: José Valim <[email protected]>
1 parent 0f7a968 commit 17c4c4d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/elixir/lib/uri.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ defmodule URI do
310310

311311
def parse(s) when is_binary(s) do
312312
# From http://tools.ietf.org/html/rfc3986#appendix-B
313-
regex = ~r/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/
313+
regex = ~r/^(([a-z][a-z0-9\+\-\.]*):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/i
314314
parts = nillify(Regex.run(regex, s))
315315

316316
destructure [_, _, scheme, _, authority, path, _, query, _, fragment], parts

lib/elixir/test/elixir/uri_test.exs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ defmodule URITest do
149149
end
150150

151151
test :parse_bad_uris do
152-
assert URI.parse("https:??@?F?@#>F//23/")
153152
assert URI.parse("")
154-
assert URI.parse(":https")
155-
assert URI.parse("https")
153+
assert URI.parse("https:??@?F?@#>F//23/")
154+
155+
assert URI.parse(":https").path == ":https"
156+
assert URI.parse("https").path == "https"
157+
assert URI.parse("ht\0tps://foo.com").path == "ht\0tps://foo.com"
156158
end
157159

158160
test :ipv6_addresses do

0 commit comments

Comments
 (0)