From 04431d1be1929080575ed14d527277d6962af2db Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Tue, 13 Jan 2026 11:07:13 +0100 Subject: [PATCH 1/4] chore: update CI --- .github/workflows/ci.yml | 5 +---- .rustfmt.toml | 2 +- rust-toolchain.toml | 3 +++ 3 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c4e513..13dbf1b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,10 +15,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v2 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - with: - components: clippy,rustfmt + - uses: dsherret/rust-toolchain-file@v1 - name: Format run: rustfmt --check src/lib.rs diff --git a/.rustfmt.toml b/.rustfmt.toml index 89ad875..265a90f 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,4 +1,4 @@ # Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. max_width = 80 tab_spaces = 2 -edition = "2018" \ No newline at end of file +edition = "2024" \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..1a21655 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.92.0" +components = ["rustfmt", "clippy"] From a620d8159d835308971904528c5579a7be5ef2cf Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Tue, 13 Jan 2026 11:09:22 +0100 Subject: [PATCH 2/4] fmt --- Cargo.toml | 2 +- src/component.rs | 4 ++-- src/constructor_parser.rs | 2 +- src/lib.rs | 6 +++--- src/matcher.rs | 2 +- src/parser.rs | 2 +- src/quirks.rs | 4 ++-- src/tokenizer.rs | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index add718b..a63c2ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "urlpattern" version = "0.4.2" authors = ["the Deno authors", "crowlKats "] -edition = "2021" +edition = "2024" description = "rust-urlpattern is a Rust implementation of the URLPattern standard" repository = "https://github.com/denoland/rust-urlpattern" license = "MIT" diff --git a/src/component.rs b/src/component.rs index c3baf4c..ee746c9 100644 --- a/src/component.rs +++ b/src/component.rs @@ -1,17 +1,17 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +use crate::Error; use crate::canonicalize_and_process::escape_pattern_string; use crate::matcher::InnerMatcher; use crate::matcher::Matcher; +use crate::parser::FULL_WILDCARD_REGEXP_VALUE; use crate::parser::Options; use crate::parser::Part; use crate::parser::PartModifier; use crate::parser::PartType; use crate::parser::RegexSyntax; -use crate::parser::FULL_WILDCARD_REGEXP_VALUE; use crate::regexp::RegExp; use crate::tokenizer::is_valid_name_codepoint; -use crate::Error; use std::fmt::Write; // Ref: https://wicg.github.io/urlpattern/#component diff --git a/src/constructor_parser.rs b/src/constructor_parser.rs index 4dbf754..8f81fb0 100644 --- a/src/constructor_parser.rs +++ b/src/constructor_parser.rs @@ -1,10 +1,10 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +use crate::UrlPatternInit; use crate::error::Error; use crate::regexp::RegExp; use crate::tokenizer::Token; use crate::tokenizer::TokenType; -use crate::UrlPatternInit; // Ref: https://wicg.github.io/urlpattern/#constructor-string-parser-state #[derive(Debug, Eq, PartialEq)] diff --git a/src/lib.rs b/src/lib.rs index 090b5c5..6fc2801 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,10 +20,10 @@ use serde::Deserialize; use serde::Serialize; use url::Url; +use crate::canonicalize_and_process::ProcessType; use crate::canonicalize_and_process::is_special_scheme; use crate::canonicalize_and_process::process_base_url; use crate::canonicalize_and_process::special_scheme_default_port; -use crate::canonicalize_and_process::ProcessType; use crate::component::Component; use crate::regexp::RegExp; @@ -648,11 +648,11 @@ mod tests { use serde::Serialize; use url::Url; - use crate::quirks; - use crate::quirks::StringOrInit; use crate::UrlPatternComponentResult; use crate::UrlPatternOptions; use crate::UrlPatternResult; + use crate::quirks; + use crate::quirks::StringOrInit; use super::UrlPattern; use super::UrlPatternInit; diff --git a/src/matcher.rs b/src/matcher.rs index ad1195d..6f7c810 100644 --- a/src/matcher.rs +++ b/src/matcher.rs @@ -1,5 +1,5 @@ -use crate::regexp::RegExp; use crate::Error; +use crate::regexp::RegExp; #[derive(Debug)] /// A structured representation of a URLPattern matcher, which can be used to diff --git a/src/parser.rs b/src/parser.rs index 27f32fa..8051530 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,9 +1,9 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +use crate::Error; use crate::error::ParserError; use crate::tokenizer::Token; use crate::tokenizer::TokenType; -use crate::Error; use serde::Deserialize; use serde::Serialize; diff --git a/src/quirks.rs b/src/quirks.rs index 79db2e4..19de090 100644 --- a/src/quirks.rs +++ b/src/quirks.rs @@ -5,11 +5,11 @@ use serde::Deserialize; use serde::Serialize; use url::Url; +pub use crate::Error; +use crate::UrlPatternOptions; pub use crate::component::Component; use crate::parser::RegexSyntax; use crate::regexp::RegExp; -pub use crate::Error; -use crate::UrlPatternOptions; #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct UrlPatternInit { diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 1b8027b..b58a075 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -1,10 +1,10 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -use crate::error::TokenizerError; use crate::Error; +use crate::error::TokenizerError; use icu_properties::{ - props::{IdContinue, IdStart}, CodePointSetDataBorrowed, + props::{IdContinue, IdStart}, }; // Ref: https://wicg.github.io/urlpattern/#tokens From f2195e0ddea61363f6c04277369d967c80a30199 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Tue, 13 Jan 2026 11:11:47 +0100 Subject: [PATCH 3/4] lint --- src/lib.rs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6fc2801..0f949e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -207,17 +207,16 @@ impl UrlPatternInit { if let Some(pathname) = &self.pathname { result.pathname = Some(pathname.clone()); - if let Some(base_url) = base_url { - if !base_url.cannot_be_a_base() - && !is_absolute_pathname(pathname, &kind) - { - let baseurl_path = url::quirks::pathname(base_url); - let slash_index = baseurl_path.rfind('/'); - if let Some(slash_index) = slash_index { - let new_pathname = baseurl_path[..=slash_index].to_string(); - result.pathname = - Some(format!("{}{}", new_pathname, result.pathname.unwrap())); - } + if let Some(base_url) = base_url + && !base_url.cannot_be_a_base() + && !is_absolute_pathname(pathname, &kind) + { + let baseurl_path = url::quirks::pathname(base_url); + let slash_index = baseurl_path.rfind('/'); + if let Some(slash_index) = slash_index { + let new_pathname = baseurl_path[..=slash_index].to_string(); + result.pathname = + Some(format!("{}{}", new_pathname, result.pathname.unwrap())); } } @@ -332,12 +331,12 @@ impl UrlPattern { )?; // If processedInit["protocol"] is a special scheme and processedInit["port"] is its corresponding default port - if let Some(protocol) = &processed_init.protocol { - if is_special_scheme(protocol) { - let default_port = special_scheme_default_port(protocol); - if default_port == processed_init.port.as_deref() { - processed_init.port = Some(String::new()) - } + if let Some(protocol) = &processed_init.protocol + && is_special_scheme(protocol) + { + let default_port = special_scheme_default_port(protocol); + if default_port == processed_init.port.as_deref() { + processed_init.port = Some(String::new()) } } From 30c35453ca2af2462931cba9ed6cb1d5a60afdb3 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Tue, 13 Jan 2026 11:13:22 +0100 Subject: [PATCH 4/4] lint tests --- src/lib.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0f949e9..199b23a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -924,12 +924,12 @@ mod tests { let match_input = quirks::process_match_input(input, base_url.as_deref()); - if let Some(ExpectedMatch::String(s)) = &case.expected_match { - if s == "error" { - assert!(match_input.is_err()); - println!("✅ Passed"); - return; - } + if let Some(ExpectedMatch::String(s)) = &case.expected_match + && s == "error" + { + assert!(match_input.is_err()); + println!("✅ Passed"); + return; }; let input = match_input.expect("failed to parse match input"); @@ -949,13 +949,13 @@ mod tests { } else { Ok(None) }; - if let Some(ExpectedMatch::String(s)) = &case.expected_match { - if s == "error" { - assert!(test_res.is_err()); - assert!(exec_res.is_err()); - println!("✅ Passed"); - return; - } + if let Some(ExpectedMatch::String(s)) = &case.expected_match + && s == "error" + { + assert!(test_res.is_err()); + assert!(exec_res.is_err()); + println!("✅ Passed"); + return; }; let expected_match = case.expected_match.map(|x| match x {