Skip to content

Commit 7d8549f

Browse files
committed
Fix base_url handling
1 parent 7bac3f2 commit 7d8549f

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

ext/urlpattern/src/lib.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,24 @@ impl UrlPattern {
2222

2323
let (base_url, options) = match base_url {
2424
Some(base_url) => {
25-
if base_url.is_kind_of(ruby.class_string()) {
26-
(Some(base_url.to_string()), options)
25+
if base_url.is_kind_of(ruby.class_hash()) {
26+
(None, Some(RHash::try_convert(base_url)?))
2727
} else {
28-
(None, options)
28+
(Some(base_url), options)
2929
}
3030
}
3131
None => (None, options),
3232
};
3333

34+
let base_url = match base_url {
35+
Some(base_url) => Some(
36+
String::try_convert(base_url)?
37+
.parse()
38+
.map_err(|e: url::ParseError| Error::new(error_class, e.to_string()))?,
39+
),
40+
None => None,
41+
};
42+
3443
let options = match options {
3544
Some(options) => urlpattern::UrlPatternOptions {
3645
ignore_case: options.fetch::<_, bool>(ruby.to_symbol("ignore_case"))?,
@@ -43,14 +52,7 @@ impl UrlPattern {
4352
Some(input) if input.is_kind_of(ruby.class_string()) => {
4453
urlpattern::UrlPatternInit::parse_constructor_string::<regex::Regex>(
4554
String::try_convert(input)?.as_str(),
46-
match base_url {
47-
Some(base_url) => {
48-
Some(base_url.parse().map_err(|e: url::ParseError| {
49-
Error::new(error_class, e.to_string())
50-
})?)
51-
}
52-
None => None,
53-
},
55+
base_url,
5456
)
5557
.map_err(|e| Error::new(error_class, e.to_string()))?
5658
}

0 commit comments

Comments
 (0)