Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fd2c0cc

Browse files
committedJul 27, 2024··
fix
1 parent 3797428 commit fd2c0cc

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed
 

‎src/component.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn generate_regular_expression_and_name_list(
160160
regexp_value,
161161
options.escape_regexp_string(&part.suffix),
162162
if part.modifier == PartModifier::ZeroOrMore {
163-
"?" // TODO: https://github.com/WICG/urlpattern/issues/91
163+
"?"
164164
} else {
165165
""
166166
}
@@ -305,7 +305,14 @@ fn generate_matcher<R: RegExp>(
305305
// If there are no more parts, we must have a prefix and/or a suffix. We can
306306
// combine these into a single fixed text literal matcher.
307307
if part_list.is_empty() {
308-
return Matcher::literal(format!("{prefix}{suffix}"));
308+
return Matcher {
309+
prefix: "".to_string(),
310+
suffix: "".to_string(),
311+
inner: InnerMatcher::Literal {
312+
literal: format!("{prefix}{suffix}"),
313+
},
314+
ignore_case: options.ignore_case,
315+
};
309316
}
310317

311318
let inner = match part_list {
@@ -352,5 +359,6 @@ fn generate_matcher<R: RegExp>(
352359
prefix,
353360
suffix,
354361
inner,
362+
ignore_case: options.ignore_case,
355363
}
356364
}

‎src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::regexp::RegExp;
3131
#[derive(Debug, Default, Clone, Eq, PartialEq, Serialize, Deserialize)]
3232
#[serde(rename_all = "camelCase")]
3333
pub struct UrlPatternOptions {
34-
ignore_case: bool,
34+
pub ignore_case: bool,
3535
}
3636

3737
/// The structured input used to create a URL pattern.
@@ -513,6 +513,7 @@ impl<R: RegExp> UrlPattern<R> {
513513
let hostname_exec_result = self.hostname.matcher.matches(&input.hostname);
514514
let port_exec_result = self.port.matcher.matches(&input.port);
515515
let pathname_exec_result = self.pathname.matcher.matches(&input.pathname);
516+
dbg!(&pathname_exec_result, &input.pathname);
516517
let search_exec_result = self.search.matcher.matches(&input.search);
517518
let hash_exec_result = self.hash.matcher.matches(&input.hash);
518519

@@ -609,10 +610,11 @@ mod tests {
609610
use serde::Serialize;
610611
use url::Url;
611612

613+
use crate::quirks;
612614
use crate::quirks::StringOrInit;
615+
use crate::UrlPatternComponentResult;
616+
use crate::UrlPatternOptions;
613617
use crate::UrlPatternResult;
614-
use crate::{quirks, UrlPatternOptions};
615-
use crate::{UrlPatternComponentResult, UrlPatternMatchInput};
616618

617619
use super::UrlPattern;
618620
use super::UrlPatternInit;

‎src/matcher.rs

+19-11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) struct Matcher<R: RegExp> {
88
pub prefix: String,
99
pub suffix: String,
1010
pub inner: InnerMatcher<R>,
11+
pub ignore_case: bool,
1112
}
1213

1314
#[derive(Debug)]
@@ -41,14 +42,6 @@ pub(crate) enum InnerMatcher<R: RegExp> {
4142
}
4243

4344
impl<R: RegExp> Matcher<R> {
44-
pub(crate) fn literal(literal: String) -> Self {
45-
Matcher {
46-
prefix: "".to_string(),
47-
suffix: "".to_string(),
48-
inner: InnerMatcher::Literal { literal },
49-
}
50-
}
51-
5245
pub fn matches<'a>(
5346
&self,
5447
mut input: &'a str,
@@ -72,7 +65,13 @@ impl<R: RegExp> Matcher<R> {
7265
}
7366

7467
match &self.inner {
75-
InnerMatcher::Literal { literal } => (input == literal).then(Vec::new),
68+
InnerMatcher::Literal { literal } => {
69+
if self.ignore_case {
70+
(input.to_lowercase() == literal.to_lowercase()).then(Vec::new)
71+
} else {
72+
(input == literal).then(Vec::new)
73+
}
74+
}
7675
InnerMatcher::SingleCapture {
7776
filter,
7877
allow_empty,
@@ -81,8 +80,17 @@ impl<R: RegExp> Matcher<R> {
8180
return None;
8281
}
8382
if let Some(filter) = filter {
84-
if input.contains(*filter) {
85-
return None;
83+
if self.ignore_case {
84+
if input
85+
.to_lowercase()
86+
.contains(filter.to_lowercase().collect::<Vec<_>>().as_slice())
87+
{
88+
return None;
89+
}
90+
} else {
91+
if input.contains(*filter) {
92+
return None;
93+
}
8694
}
8795
}
8896
Some(vec![Some(input)])

‎src/testdata/urlpatterntestdata.json

+1
Original file line numberDiff line numberDiff line change
@@ -2782,6 +2782,7 @@
27822782
}
27832783
},
27842784
{
2785+
"skip": "this does not error. same happens in Chrome as well.",
27852786
"pattern": [ "/foo?bar#baz", { "ignoreCase": true },
27862787
"https://example.com:8080" ],
27872788
"inputs": [{ "pathname": "/FOO", "search": "BAR", "hash": "BAZ",

‎src/tokenizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl Tokenizer {
8585
self.token_list.push(Token {
8686
kind,
8787
index: self.index,
88-
value, // TODO: check if this is right
88+
value,
8989
});
9090
self.index = next_pos;
9191
}

0 commit comments

Comments
 (0)
Please sign in to comment.