Skip to content

Commit 1480e30

Browse files
author
Nazarii Sheremet
authored
Merge pull request #7 from nsheremet/develop
Add new REGEXP for url
2 parents 242435d + aa6f4ad commit 1480e30

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

mrblib/http.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class HTTP
22
attr_accessor :url
33

44
# TODO need better regexp
5-
URL_REGEXP = /^((http[s]?):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/
5+
URL_REGEXP = /^(http:\\.|https:\\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/
66
HOST_REGEXP = /^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)/
77

88
HTTP_VERSION = 'HTTP/1.1'
@@ -14,6 +14,7 @@ class HTTP
1414
port: 80,
1515
ssl_port: 443,
1616
accept: '*/*',
17+
path: '/'
1718
}
1819

1920
##
@@ -249,7 +250,7 @@ def parse_url(url, port)
249250
@url[:ssl_enabled] = !!url[/^(https)/]
250251

251252
@url[:host] = url[HOST_REGEXP].split(url[/^(http[s]?)/] + '://')[1]
252-
@url[:path] = url.split(url[HOST_REGEXP])[1]
253+
@url[:path] = url.split(url[HOST_REGEXP])[1] || DEFAULTS[:path]
253254
else
254255
raise ArgumentError
255256
end

test/http.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def run_with_catching_error(&b)
1616
end
1717

1818
assert("make a request") do
19-
http = HTTP.new("http://mruby.org/about/")
19+
http = HTTP.new("http://mruby.org")
2020
response = http.request("GET")
2121

2222
assert_equal response.nil?, false

0 commit comments

Comments
 (0)