Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
max_width = 80
tab_spaces = 2
edition = "2018"
edition = "2024"
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "urlpattern"
version = "0.4.2"
authors = ["the Deno authors", "crowlKats <crowlkats@toaxl.com>"]
edition = "2021"
edition = "2024"
description = "rust-urlpattern is a Rust implementation of the URLPattern standard"
repository = "https://github.com/denoland/rust-urlpattern"
license = "MIT"
Expand Down
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.92.0"
components = ["rustfmt", "clippy"]
4 changes: 2 additions & 2 deletions src/component.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/constructor_parser.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
65 changes: 32 additions & 33 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()));
}
}

Expand Down Expand Up @@ -332,12 +331,12 @@ impl<R: RegExp> UrlPattern<R> {
)?;

// 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())
}
}

Expand Down Expand Up @@ -648,11 +647,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;
Expand Down Expand Up @@ -925,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");
Expand All @@ -950,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 {
Expand Down
2 changes: 1 addition & 1 deletion src/matcher.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/quirks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down