Skip to content

Commit db92dd2

Browse files
committed
Merge branch 'master' into no_std
2 parents 67d2a4c + 6385c81 commit db92dd2

File tree

30 files changed

+2102
-438
lines changed

30 files changed

+2102
-438
lines changed

.github/workflows/codecov.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ jobs:
99
coverage:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v1
13-
- uses: actions-rs/toolchain@v1
12+
- uses: actions/checkout@v3
13+
- uses: dtolnay/rust-toolchain@stable
14+
- uses: taiki-e/install-action@v2
1415
with:
15-
profile: minimal
16-
toolchain: stable
17-
override: true
18-
- uses: actions-rs/tarpaulin@v0.1
19-
- uses: codecov/codecov-action@v2.1.0
16+
tool: cargo-tarpaulin
17+
- run: cargo tarpaulin --out Xml
18+
- uses: codecov/codecov-action@v3
2019
# A codecov token is not needed for public repos if the repo is linked
2120
# on codecov.io. See https://docs.codecov.com/docs/frequently-asked-questions#where-is-the-repository-upload-token-found
22-
- uses: actions/upload-artifact@v1
21+
- uses: actions/upload-artifact@v2
2322
with:
2423
name: code-coverage-report
2524
path: cobertura.xml

.github/workflows/main.yml

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,87 +5,73 @@ on:
55
branches: ["master"]
66
pull_request:
77

8+
env:
9+
CARGO_NET_GIT_FETCH_WITH_CLI: true
10+
811
jobs:
912
Test:
1013
strategy:
1114
matrix:
1215
os: [ubuntu-latest, macos-latest, windows-latest]
13-
rust: [1.45.0, stable, beta, nightly]
16+
rust: [1.56.0, stable, beta, nightly]
1417
exclude:
1518
- os: macos-latest
16-
rust: 1.45.0
19+
rust: 1.56.0
1720
- os: windows-latest
18-
rust: 1.45.0
21+
rust: 1.56.0
1922
- os: macos-latest
2023
rust: beta
2124
- os: windows-latest
2225
rust: beta
2326
- os: macos-latest
2427
rust: nightly
25-
- os: windows-latest
26-
rust: nightly
2728

2829
runs-on: ${{ matrix.os }}
2930

3031
steps:
31-
- uses: actions/checkout@v2
32-
- uses: actions-rs/toolchain@v1
32+
- uses: actions/checkout@v3
33+
- uses: dtolnay/rust-toolchain@master
3334
with:
34-
profile: minimal
3535
toolchain: ${{ matrix.rust }}
36-
override: true
37-
- uses: actions-rs/cargo@v1
38-
with:
39-
command: build
40-
args: --all-targets
41-
- uses: actions-rs/cargo@v1
42-
with:
43-
command: test
44-
args: --all-features
45-
- uses: actions-rs/cargo@v1
46-
# --no-default-features only available since 1.51.0
47-
if: matrix.rust != '1.45.0'
48-
with:
49-
command: test
50-
args: --no-default-features
36+
- run: cargo build --all-targets
37+
# Run tests
38+
- name: Run tests
39+
run: cargo test
40+
# Run tests enabling the serde feature
41+
- name: Run tests with the serde feature
42+
run: cargo test --features "url/serde,url/expose_internals"
43+
# The #[debugger_visualizer] attribute is currently gated behind an unstable feature flag.
44+
# In order to test the visualizers for the url crate, they have to be tested on a nightly build.
45+
- name: Run debugger_visualizer tests
46+
if: |
47+
matrix.os == 'windows-latest' &&
48+
matrix.rust == 'nightly'
49+
run: cargo test --test debugger_visualizer --features "url/serde,url/debugger_visualizer" -- --test-threads=1
50+
- name: Test `no_std` support
51+
run: cargo test --no-default-features --features=alloc
5152

5253
WASM:
5354
runs-on: ubuntu-latest
5455
steps:
55-
- uses: actions/checkout@v2
56-
- uses: actions-rs/toolchain@v1
57-
with:
58-
profile: minimal
59-
toolchain: stable
60-
target: wasm32-unknown-unknown
61-
override: true
62-
- uses: actions-rs/cargo@v1
56+
- uses: actions/checkout@v3
57+
- uses: dtolnay/rust-toolchain@stable
6358
with:
64-
command: build
65-
args: --target wasm32-unknown-unknown
59+
targets: wasm32-unknown-unknown
60+
- run: cargo build --target wasm32-unknown-unknown
6661

6762
Lint:
6863
runs-on: ubuntu-latest
6964
steps:
70-
- uses: actions/checkout@v2
71-
- uses: actions-rs/toolchain@v1
65+
- uses: actions/checkout@v3
66+
- uses: dtolnay/rust-toolchain@stable
7267
with:
73-
profile: minimal
74-
toolchain: stable
75-
override: true
7668
components: rustfmt, clippy
77-
- uses: actions-rs/cargo@v1
78-
with:
79-
command: fmt
80-
args: --all -- --check
81-
- uses: actions-rs/cargo@v1
69+
- run: cargo fmt --all --check
70+
- run: cargo clippy --workspace --all-targets -- -D warnings
8271
if: always()
83-
with:
84-
command: clippy
85-
args: --workspace --all-targets -- -D warnings
8672

8773
Audit:
8874
runs-on: ubuntu-latest
8975
steps:
90-
- uses: actions/checkout@v1
76+
- uses: actions/checkout@v3
9177
- uses: EmbarkStudios/cargo-deny-action@v1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ URL library for Rust, based on the [URL Standard](https://url.spec.whatwg.org/).
1111

1212
[Documentation](https://docs.rs/url/)
1313

14-
Please see [UPGRADING.md](https://github.com/servo/rust-url/blob/master/UPGRADING.md) if you are upgrading from 0.x to 1.x.
14+
Please see [UPGRADING.md](https://github.com/servo/rust-url/blob/master/UPGRADING.md) if you are upgrading from a previous version.

SECURITY.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
| Version | Supported |
6+
| ------- | ------------------ |
7+
| 2.2.x | :white_check_mark: |
8+
9+
## Reporting a Vulnerability
10+
11+
The most secure way to report a vulnerability while this crate is maintained by a Mozilla contributor is by reporting a bug on the Bugzilla issue tracker using this [link](https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=Networking&groups=network-core-security&short_desc=[rust-url]%20DESCRIPTION&bug_type=defect).
12+
13+
Alternatively, you may send an email to valentin AT mozilla DOT com.

data-url/Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
[package]
22
name = "data-url"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
authors = ["Simon Sapin <simon.sapin@exyr.org>"]
55
description = "Processing of data: URL according to WHATWG’s Fetch Standard"
6+
categories = ["no_std"]
67
repository = "https://github.com/servo/rust-url"
78
license = "MIT OR Apache-2.0"
89
edition = "2018"
910
autotests = false
10-
rust-version = "1.45"
11+
rust-version = "1.51"
12+
13+
[features]
14+
default = ["std"]
15+
std = ["alloc"]
16+
alloc = []
1117

1218
[dev-dependencies]
1319
tester = "0.9"

data-url/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@
1616
//! ```
1717
#![no_std]
1818

19+
// For forwards compatibility
20+
#[cfg(feature = "std")]
21+
extern crate std as _;
22+
1923
#[macro_use]
2024
extern crate alloc;
2125

26+
#[cfg(not(feature = "alloc"))]
27+
compile_error!("the `alloc` feature must be enabled");
28+
2229
use alloc::{string::String, vec::Vec};
2330

2431
macro_rules! require {

data-url/src/mime.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ impl Mime {
1818
{
1919
self.parameters
2020
.iter()
21-
.find(|&&(ref n, _)| name == &**n)
22-
.map(|&(_, ref v)| &**v)
21+
.find(|&(n, _)| name == &**n)
22+
.map(|(_, v)| &**v)
2323
}
2424
}
2525

@@ -125,7 +125,7 @@ fn parse_parameters(s: &str, parameters: &mut Vec<(String, String)>) {
125125
}
126126

127127
fn contains(parameters: &[(String, String)], name: &str) -> bool {
128-
parameters.iter().any(|&(ref n, _)| n == name)
128+
parameters.iter().any(|(n, _)| n == name)
129129
}
130130

131131
fn valid_value(s: &str) -> bool {
@@ -141,7 +141,7 @@ impl fmt::Display for Mime {
141141
f.write_str(&self.type_)?;
142142
f.write_str("/")?;
143143
f.write_str(&self.subtype)?;
144-
for &(ref name, ref value) in &self.parameters {
144+
for (name, value) in &self.parameters {
145145
f.write_str(";")?;
146146
f.write_str(name)?;
147147
f.write_str("=")?;

debug_metadata/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
## Debugger Visualizers
2+
3+
Many languages and debuggers enable developers to control how a type is
4+
displayed in a debugger. These are called "debugger visualizations" or "debugger
5+
views".
6+
7+
The Windows debuggers (WinDbg\CDB) support defining custom debugger visualizations using
8+
the `Natvis` framework. To use Natvis, developers write XML documents using the natvis
9+
schema that describe how debugger types should be displayed with the `.natvis` extension.
10+
(See: https://docs.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects?view=vs-2019)
11+
The Natvis files provide patterns which match type names a description of how to display
12+
those types.
13+
14+
The Natvis schema can be found either online (See: https://code.visualstudio.com/docs/cpp/natvis#_schema)
15+
or locally at `<VS Installation Folder>\Xml\Schemas\1033\natvis.xsd`.
16+
17+
The GNU debugger (GDB) supports defining custom debugger views using Pretty Printers.
18+
Pretty printers are written as python scripts that describe how a type should be displayed
19+
when loaded up in GDB/LLDB. (See: https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing.html#Pretty-Printing)
20+
The pretty printers provide patterns, which match type names, and for matching
21+
types, descibe how to display those types. (For writing a pretty printer, see: https://sourceware.org/gdb/onlinedocs/gdb/Writing-a-Pretty_002dPrinter.html#Writing-a-Pretty_002dPrinter).
22+
23+
### Embedding Visualizers
24+
25+
Through the use of the currently unstable `#[debugger_visualizer]` attribute, the `url`
26+
crate can embed debugger visualizers into the crate metadata.
27+
28+
Currently the two types of visualizers supported are Natvis and Pretty printers.
29+
30+
For Natvis files, when linking an executable with a crate that includes Natvis files,
31+
the MSVC linker will embed the contents of all Natvis files into the generated `PDB`.
32+
33+
For pretty printers, the compiler will encode the contents of the pretty printer
34+
in the `.debug_gdb_scripts` section of the `ELF` generated.
35+
36+
### Testing Visualizers
37+
38+
The `url` crate supports testing debugger visualizers defined for this crate. The entry point for
39+
these tests are `tests/debugger_visualizer.rs`. These tests are defined using the `debugger_test` and
40+
`debugger_test_parser` crates. The `debugger_test` crate is a proc macro crate which defines a
41+
single proc macro attribute, `#[debugger_test]`. For more detailed information about this crate,
42+
see https://crates.io/crates/debugger_test. The CI pipeline for the `url` crate has been updated
43+
to run the debugger visualizer tests to ensure debugger visualizers do not become broken/stale.
44+
45+
The `#[debugger_test]` proc macro attribute may only be used on test functions and will run the
46+
function under the debugger specified by the `debugger` meta item.
47+
48+
This proc macro attribute has 3 required values:
49+
50+
1. The first required meta item, `debugger`, takes a string value which specifies the debugger to launch.
51+
2. The second required meta item, `commands`, takes a string of new line (`\n`) separated list of debugger
52+
commands to run.
53+
3. The third required meta item, `expected_statements`, takes a string of new line (`\n`) separated list of
54+
statements that must exist in the debugger output. Pattern matching through regular expressions is also
55+
supported by using the `pattern:` prefix for each expected statement.
56+
57+
#### Example:
58+
59+
```rust
60+
#[debugger_test(
61+
debugger = "cdb",
62+
commands = "command1\ncommand2\ncommand3",
63+
expected_statements = "statement1\nstatement2\nstatement3")]
64+
fn test() {
65+
66+
}
67+
```
68+
69+
Using a multiline string is also supported, with a single debugger command/expected statement per line:
70+
71+
```rust
72+
#[debugger_test(
73+
debugger = "cdb",
74+
commands = "
75+
command1
76+
command2
77+
command3",
78+
expected_statements = "
79+
statement1
80+
pattern:statement[0-9]+
81+
statement3")]
82+
fn test() {
83+
84+
}
85+
```
86+
87+
In the example above, the second expected statement uses pattern matching through a regular expression
88+
by using the `pattern:` prefix.
89+
90+
#### Testing Locally
91+
92+
Currently, only Natvis visualizations have been defined for the `url` crate via `debug_metadata/url.natvis`,
93+
which means the `tests/debugger_visualizer.rs` tests need to be run on Windows using the `*-pc-windows-msvc` targets.
94+
To run these tests locally, first ensure the debugging tools for Windows are installed or install them following
95+
the steps listed here, [Debugging Tools for Windows](https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/).
96+
Once the debugging tools have been installed, the tests can be run in the same manner as they are in the CI
97+
pipeline.
98+
99+
#### Note
100+
101+
When running the debugger visualizer tests, `tests/debugger_visualizer.rs`, they need to be run consecutively
102+
and not in parallel. This can be achieved by passing the flag `--test-threads=1` to rustc. This is due to
103+
how the debugger tests are run. Each test marked with the `#[debugger_test]` attribute launches a debugger
104+
and attaches it to the current test process. If tests are running in parallel, the test will try to attach
105+
a debugger to the current process which may already have a debugger attached causing the test to fail.
106+
107+
For example:
108+
109+
```
110+
cargo test --test debugger_visualizer --features debugger_visualizer -- --test-threads=1
111+
```

debug_metadata/url.natvis

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
3+
<Type Name="url::Url">
4+
<Intrinsic Name="ptr" Expression="serialization.vec.buf.ptr.pointer.pointer" />
5+
<DisplayString>{serialization}</DisplayString>
6+
<Expand>
7+
<Synthetic Name="[scheme]">
8+
<DisplayString>{(char*)(ptr()),[scheme_end]s8}</DisplayString>
9+
</Synthetic>
10+
<Synthetic Name="[username]" Condition="username_end > (scheme_end + 3)">
11+
<!-- Add 3 to the scheme end to account for the scheme separator which is '://' -->
12+
<DisplayString>{(char*)(ptr()+(scheme_end + 3)),[((username_end)-(scheme_end + 3))]s8}</DisplayString>
13+
</Synthetic>
14+
<Synthetic Name="[host]" Condition="host.tag != 0">
15+
<DisplayString>{(char*)(ptr()+host_start),[host_end-host_start]s8}</DisplayString>
16+
</Synthetic>
17+
<Synthetic Name="[port]" Condition="port.tag == 1">
18+
<DisplayString>{port.variant1.value.__0,d}</DisplayString>
19+
</Synthetic>
20+
<Synthetic Name="[path]">
21+
<DisplayString Condition="query_start.tag == 0 &amp;&amp; fragment_start.tag == 0">{(char*)(ptr()+path_start),[(serialization.vec.len-path_start)]s8}</DisplayString>
22+
<DisplayString Condition="query_start.tag == 1">{(char*)(ptr()+path_start),[(query_start.variant1.value.__0-path_start)]s8}</DisplayString>
23+
<DisplayString Condition="fragment_start.tag == 1">{(char*)(ptr()+path_start),[(fragment_start.variant1.value.__0-path_start)]s8}</DisplayString>
24+
</Synthetic>
25+
<Synthetic Name="[query]" Condition="query_start.tag == 1">
26+
<DisplayString Condition="fragment_start.tag == 0">{(char*)(ptr()+query_start.variant1.value.__0+1),[((serialization.vec.len)-(query_start.variant1.value.__0+1))]s8}</DisplayString>
27+
<DisplayString Condition="fragment_start.tag == 1">{(char*)(ptr()+query_start.variant1.value.__0+1),[((fragment_start.variant1.value.__0)-(query_start.variant1.value.__0+1))]s8}</DisplayString>
28+
</Synthetic>
29+
<Synthetic Name="[fragment]" Condition="fragment_start.tag == 1">
30+
<DisplayString>{(char*)(ptr()+fragment_start.variant1.value.__0+1),[(serialization.vec.len-fragment_start.variant1.value.__0-1)]s8}</DisplayString>
31+
</Synthetic>
32+
</Expand>
33+
</Type>
34+
</AutoVisualizer>

0 commit comments

Comments
 (0)