2017-07-01 16:09:13 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:47:31 -04:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
2012-12-19 15:54:47 -05:00
|
|
|
|
|
|
|
module ActionDispatch
|
|
|
|
module Journey
|
|
|
|
class Router
|
2012-12-31 12:36:30 -05:00
|
|
|
class TestUtils < ActiveSupport::TestCase
|
2012-12-19 15:54:47 -05:00
|
|
|
def test_path_escape
|
2014-04-07 02:34:21 -04:00
|
|
|
assert_equal "a/b%20c+d%25", Utils.escape_path("a/b c+d%")
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
2014-04-20 05:08:32 -04:00
|
|
|
def test_segment_escape
|
|
|
|
assert_equal "a%2Fb%20c+d%25", Utils.escape_segment("a/b c+d%")
|
|
|
|
end
|
|
|
|
|
2012-12-19 15:54:47 -05:00
|
|
|
def test_fragment_escape
|
2014-04-07 02:34:21 -04:00
|
|
|
assert_equal "a/b%20c+d%25?e", Utils.escape_fragment("a/b c+d%?e")
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_uri_unescape
|
|
|
|
assert_equal "a/b c+d", Utils.unescape_uri("a%2Fb%20c+d")
|
|
|
|
end
|
2013-10-23 17:44:23 -04:00
|
|
|
|
2014-07-10 04:58:46 -04:00
|
|
|
def test_uri_unescape_with_utf8_string
|
2017-07-01 16:09:13 -04:00
|
|
|
assert_equal "Šašinková", Utils.unescape_uri("%C5%A0a%C5%A1inkov%C3%A1".dup.force_encoding(Encoding::US_ASCII))
|
2014-07-10 04:58:46 -04:00
|
|
|
end
|
|
|
|
|
2013-10-23 17:44:23 -04:00
|
|
|
def test_normalize_path_not_greedy
|
|
|
|
assert_equal "/foo%20bar%20baz", Utils.normalize_path("/foo%20bar%20baz")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_normalize_path_uppercase
|
|
|
|
assert_equal "/foo%AAbar%AAbaz", Utils.normalize_path("/foo%aabar%aabaz")
|
|
|
|
end
|
2017-05-12 14:12:40 -04:00
|
|
|
|
|
|
|
def test_normalize_path_maintains_string_encoding
|
|
|
|
path = "/foo%AAbar%AAbaz".b
|
|
|
|
assert_equal Encoding::ASCII_8BIT, Utils.normalize_path(path).encoding
|
|
|
|
end
|
2017-07-12 06:48:31 -04:00
|
|
|
|
|
|
|
def test_normalize_path_with_nil
|
2017-07-24 16:20:53 -04:00
|
|
|
assert_equal "/", Utils.normalize_path(nil)
|
2017-07-12 06:48:31 -04:00
|
|
|
end
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|