1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
//! Test cases for issues reported on GitHub.
#[macro_use]
mod utils;
use iri_string::types::UriReferenceStr;
mod issue_17 {
use super::*;
#[test]
fn ipv6_literal_authority_host() {
let uri = UriReferenceStr::new("//[::1]").expect("valid relative URI");
let authority = uri
.authority_components()
.expect("the URI has authority `[::1]`");
assert_eq!(authority.host(), "[::1]");
}
#[test]
fn extra_trailing_colon_in_ipv6_literal() {
assert!(UriReferenceStr::new("//[::1:]").is_err());
}
#[test]
fn ipvfuture_literal_capital_v() {
assert!(UriReferenceStr::new("//[v0.0]").is_ok());
assert!(UriReferenceStr::new("//[V0.0]").is_ok());
}
#[test]
fn ipvfuture_empty_part() {
assert!(
UriReferenceStr::new("//[v0.]").is_err(),
"address should not be empty"
);
assert!(
UriReferenceStr::new("//[v.0]").is_err(),
"version should not be empty"
);
assert!(
UriReferenceStr::new("//[v.]").is_err(),
"neither address nor version should be empty"
);
}
}
mod issue_36 {
use super::*;
#[cfg(feature = "alloc")]
use iri_string::format::ToDedicatedString;
use iri_string::types::UriAbsoluteStr;
// "/.//.".resolve_against("a:/")
// => "a:" + remove_dot_segments("/.//.")
//
// STEP OUTPUT BUFFER INPUT BUFFER
// 1 : /.//.
// 2B: //.
// 2E: / /.
// 2B: / /
// 2E: //
// (see RFC 3986 section 5.2.4 for this notation.)
//
// => "a://"
//
// However, this is invalid since it should be semantically
// `<scheme="a">:<path="//">` but this string will be parsed as
// `<scheme="a">://<path="">`. So, `./` should be inserted to break
// `//` at the beginning of the path part.
#[test]
fn abnormal_resolution() {
let base = UriAbsoluteStr::new("a:/").expect("valid absolute URI");
{
let relative = UriReferenceStr::new("/.//.").expect("valid relative URI");
let result = relative.resolve_against(base);
assert!(
result.ensure_rfc3986_normalizable().is_err(),
"strict RFC 3986 resolution should fail for base={:?}, ref={:?}",
base,
relative
);
assert_eq_display!(
result,
"a:/.//",
"resolution result will be modified using serialization by WHATWG URL Standard"
);
}
{
let relative = UriReferenceStr::new(".//.").expect("valid relative URI");
let result = relative.resolve_against(base);
assert!(
result.ensure_rfc3986_normalizable().is_err(),
"strict RFC 3986 resolution should fail for base={:?}, ref={:?}",
base,
relative
);
assert_eq_display!(
result,
"a:/.//",
"resolution result will be modified using serialization by WHATWG URL Standard"
);
}
}
#[test]
fn abnormal_normalization() {
let uri = UriAbsoluteStr::new("a:/.//.").expect("valid absolute URI");
let normalized = uri.normalize();
assert!(
normalized.ensure_rfc3986_normalizable().is_err(),
"strict RFC 3986 normalization should fail for uri={:?}",
uri
);
assert_eq_display!(
normalized,
"a:/.//",
"normalization result will be modified using serialization by WHATWG URL Standard"
);
#[cfg(feature = "alloc")]
{
assert!(
!normalized.to_dedicated_string().is_normalized_rfc3986(),
"not normalizable by strict RFC 3986 algorithm"
);
}
}
#[test]
fn abnormal_normalization2() {
{
let uri = UriAbsoluteStr::new("a:/bar//.").expect("valid absolute URI");
assert_eq_display!(uri.normalize(), "a:/bar//");
}
{
let uri = UriAbsoluteStr::new("a:/bar/..//.").expect("valid absolute URI");
assert_eq_display!(
uri.normalize(),
"a:/.//",
"normalization result will be modified using serialization by WHATWG URL Standard"
);
}
{
let uri = UriAbsoluteStr::new("a:/.//bar/.").expect("valid absolute URI");
assert_eq_display!(
uri.normalize(),
"a:/.//bar/",
"normalization result will be modified using serialization by WHATWG URL Standard"
);
}
{
let uri = UriAbsoluteStr::new("a:/././././././foo/./.././././././././././/.")
.expect("valid absolute URI");
assert_eq_display!(
uri.normalize(),
"a:/.//",
"normalization result will be modified using serialization by WHATWG URL Standard"
);
}
}
#[test]
fn normalization_pct_triplet_loss() {
let uri = UriAbsoluteStr::new("a://%92%99").expect("valid absolute URI");
assert_eq_display!(uri.normalize(), "a://%92%99");
// Other problems are found during fixing this bug. The test cases for
// them have been added to generic test case data source.
}
}
/// <https://github.com/lo48576/iri-string/pull/46>
#[cfg(feature = "alloc")]
mod issue_46 {
use iri_string::types::{UriFragmentStr, UriRelativeString};
#[test]
fn set_fragment_to_relative() {
let mut uri =
UriRelativeString::try_from("//user:password@example.com/path?query#frag.old")
.expect("valid relative URI");
assert_eq!(uri, "//user:password@example.com/path?query#frag.old");
assert_eq!(uri.fragment_str(), Some("frag.old"));
uri.set_fragment(None);
assert_eq!(uri, "//user:password@example.com/path?query");
assert_eq!(uri.fragment(), None);
let frag_new = UriFragmentStr::new("frag-new").expect("valid URI fragment");
uri.set_fragment(Some(frag_new));
assert_eq!(uri.fragment_str(), Some("frag-new"));
}
}
|