|
12 | 12 | //! you probably want to use `Url` method instead. |
13 | 13 |
|
14 | 14 | use parser::{default_port, Context, Input, Parser, SchemeType}; |
| 15 | +use std::cell::RefCell; |
| 16 | +use SyntaxViolation; |
15 | 17 | use {idna, Host, ParseError, Position, Url}; |
16 | 18 |
|
17 | 19 | /// https://url.spec.whatwg.org/#dom-url-domaintoascii |
@@ -103,15 +105,18 @@ pub fn set_host(url: &mut Url, new_host: &str) -> Result<(), ()> { |
103 | 105 | if url.cannot_be_a_base() { |
104 | 106 | return Err(()); |
105 | 107 | } |
| 108 | + // Host parsing rules are strict, |
| 109 | + // We don't want to trim the input |
| 110 | + let input = Input::no_trim(new_host); |
106 | 111 | let host; |
107 | 112 | let opt_port; |
108 | 113 | { |
109 | 114 | let scheme = url.scheme(); |
110 | 115 | let scheme_type = SchemeType::from(scheme); |
111 | 116 | let result = if scheme_type == SchemeType::File { |
112 | | - Parser::get_file_host(Input::new(new_host)) |
| 117 | + Parser::get_file_host(input) |
113 | 118 | } else { |
114 | | - Parser::parse_host(Input::new(new_host), scheme_type) |
| 119 | + Parser::parse_host(input, scheme_type) |
115 | 120 | }; |
116 | 121 | match result { |
117 | 122 | Ok((h, remaining)) => { |
@@ -160,11 +165,14 @@ pub fn set_hostname(url: &mut Url, new_hostname: &str) -> Result<(), ()> { |
160 | 165 | if url.cannot_be_a_base() { |
161 | 166 | return Err(()); |
162 | 167 | } |
| 168 | + // Host parsing rules are strict, |
| 169 | + // We don't want to trim the input |
| 170 | + let input = Input::no_trim(new_hostname); |
163 | 171 | let scheme_type = SchemeType::from(url.scheme()); |
164 | 172 | let result = if scheme_type == SchemeType::File { |
165 | | - Parser::get_file_host(Input::new(new_hostname)) |
| 173 | + Parser::get_file_host(input) |
166 | 174 | } else { |
167 | | - Parser::parse_host(Input::new(new_hostname), scheme_type) |
| 175 | + Parser::parse_host(input, scheme_type) |
168 | 176 | }; |
169 | 177 | if let Ok((host, _remaining)) = result { |
170 | 178 | if let Host::Domain(h) = &host { |
|
0 commit comments