|
0 |
From 024ac8e9d10d195139e41b3fd97ad5222c5fb05c Mon Sep 17 00:00:00 2001
|
|
1 |
From: Nikhil Benesch <nikhil.benesch@gmail.com>
|
|
2 |
Date: Tue, 30 Jul 2019 11:16:41 -0400
|
|
3 |
Subject: [PATCH] Upgrade to url 2.0 ecosystem
|
|
4 |
|
|
5 |
The url crate recently released a backwards-incompatible update, v2.0.
|
|
6 |
As part of this upgrade, the percent-encoding code has been moved into
|
|
7 |
its own crate, titled percent-encoding, and no longer ships standard
|
|
8 |
percent encoding sets.
|
|
9 |
---
|
|
10 |
Cargo.toml | 4 ++--
|
|
11 |
src/lib.rs | 26 ++++++++++++++++++++++++--
|
|
12 |
src/parse.rs | 2 +-
|
|
13 |
3 files changed, 27 insertions(+), 5 deletions(-)
|
|
14 |
|
|
15 |
diff --git a/Cargo.toml b/Cargo.toml
|
|
16 |
index 61f0adae..8a4be92a 100644
|
|
17 |
--- a/Cargo.toml
|
|
18 |
+++ b/Cargo.toml
|
|
19 |
@@ -32,9 +32,13 @@
|
|
20 |
version = "0.1"
|
|
21 |
|
|
22 |
[dependencies.url]
|
|
23 |
-version = "1.0"
|
|
24 |
+version = "2"
|
|
25 |
+optional = true
|
|
26 |
+
|
|
27 |
+[dependencies.percent-encoding]
|
|
28 |
+version = "2"
|
|
29 |
optional = true
|
|
30 |
|
|
31 |
[features]
|
|
32 |
-percent-encode = ["url"]
|
|
33 |
+percent-encode = ["percent-encoding"]
|
|
34 |
secure = ["ring", "base64"]
|
|
35 |
diff --git a/src/lib.rs b/src/lib.rs
|
|
36 |
index c4aab99d..dc32fed1 100644
|
|
37 |
--- a/src/lib.rs
|
|
38 |
+++ b/src/lib.rs
|
|
39 |
@@ -61,7 +61,7 @@
|
|
40 |
#![doc(html_root_url = "https://docs.rs/cookie/0.12")]
|
|
41 |
#![deny(missing_docs)]
|
|
42 |
|
|
43 |
-#[cfg(feature = "percent-encode")] extern crate url;
|
|
44 |
+#[cfg(feature = "percent-encode")] extern crate percent_encoding;
|
|
45 |
extern crate time;
|
|
46 |
|
|
47 |
mod builder;
|
|
48 |
@@ -81,7 +81,7 @@ use std::str::FromStr;
|
|
49 |
use std::ascii::AsciiExt;
|
|
50 |
|
|
51 |
#[cfg(feature = "percent-encode")]
|
|
52 |
-use url::percent_encoding::{USERINFO_ENCODE_SET, percent_encode};
|
|
53 |
+use percent_encoding::{AsciiSet, percent_encode};
|
|
54 |
use time::{Tm, Duration};
|
|
55 |
|
|
56 |
use parse::parse_cookie;
|
|
57 |
@@ -905,6 +905,28 @@ impl<'c> Cookie<'c> {
|
|
58 |
}
|
|
59 |
}
|
|
60 |
|
|
61 |
+/// https://url.spec.whatwg.org/#fragment-percent-encode-set
|
|
62 |
+#[cfg(feature = "percent-encode")]
|
|
63 |
+const FRAGMENT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS.add(b' ').add(b'"').add(b'<').add(b'>').add(b'`');
|
|
64 |
+
|
|
65 |
+/// https://url.spec.whatwg.org/#path-percent-encode-set
|
|
66 |
+#[cfg(feature = "percent-encode")]
|
|
67 |
+const PATH_ENCODE_SET: &AsciiSet = &FRAGMENT_ENCODE_SET.add(b'#').add(b'?').add(b'{').add(b'}');
|
|
68 |
+
|
|
69 |
+/// https://url.spec.whatwg.org/#userinfo-percent-encode-set
|
|
70 |
+#[cfg(feature = "percent-encode")]
|
|
71 |
+const USERINFO_ENCODE_SET: &AsciiSet = &PATH_ENCODE_SET
|
|
72 |
+ .add(b'/')
|
|
73 |
+ .add(b':')
|
|
74 |
+ .add(b';')
|
|
75 |
+ .add(b'=')
|
|
76 |
+ .add(b'@')
|
|
77 |
+ .add(b'[')
|
|
78 |
+ .add(b'\\')
|
|
79 |
+ .add(b']')
|
|
80 |
+ .add(b'^')
|
|
81 |
+ .add(b'|');
|
|
82 |
+
|
|
83 |
/// Wrapper around `Cookie` whose `Display` implementation percent-encodes the
|
|
84 |
/// cookie's name and value.
|
|
85 |
///
|
|
86 |
diff --git a/src/parse.rs b/src/parse.rs
|
|
87 |
index be0a2227..f224a8c7 100644
|
|
88 |
--- a/src/parse.rs
|
|
89 |
+++ b/src/parse.rs
|
|
90 |
@@ -9,7 +9,7 @@ use std::convert::From;
|
|
91 |
use std::ascii::AsciiExt;
|
|
92 |
|
|
93 |
#[cfg(feature = "percent-encode")]
|
|
94 |
-use url::percent_encoding::percent_decode;
|
|
95 |
+use percent_encoding::percent_decode;
|
|
96 |
use time::{self, Duration};
|
|
97 |
|
|
98 |
use ::{Cookie, SameSite, CookieStr};
|