Skip to content

Commit b567a51

Browse files
committed
Remove rust-encoding support
1 parent 47e2286 commit b567a51

File tree

7 files changed

+64
-235
lines changed

7 files changed

+64
-235
lines changed

Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ serde_json = "1.0"
3636

3737
bencher = "0.1"
3838

39-
[features]
40-
query_encoding = ["encoding"]
41-
4239
[dependencies]
43-
encoding = {version = "0.2", optional = true}
4440
idna = { version = "0.1.0", path = "./idna" }
4541
matches = "0.1"
4642
percent-encoding = { version = "1.0.0", path = "./percent_encoding" }
@@ -49,6 +45,3 @@ serde = {version = "1.0", optional = true}
4945
[[bench]]
5046
name = "parse_url"
5147
harness = false
52-
53-
[package.metadata.docs.rs]
54-
features = ["query_encoding"]

src/encoding.rs

Lines changed: 0 additions & 127 deletions
This file was deleted.

src/form_urlencoded.rs

Lines changed: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
//! Converts between a string (such as an URL’s query string)
1414
//! and a sequence of (name, value) pairs.
1515
16-
use encoding::{decode_utf8_lossy, EncodingOverride};
1716
use percent_encoding::{percent_decode, percent_encode_byte};
17+
use query_encoding::{self, decode_utf8_lossy, EncodingOverride};
1818
use std::borrow::{Borrow, Cow};
19-
use std::fmt;
2019
use std::str;
2120

2221
/// Convert a byte string in the `application/x-www-form-urlencoded` syntax
@@ -31,7 +30,7 @@ pub fn parse(input: &[u8]) -> Parse {
3130
Parse { input: input }
3231
}
3332
/// The return type of `parse()`.
34-
#[derive(Copy, Clone, Debug)]
33+
#[derive(Copy, Clone)]
3534
pub struct Parse<'a> {
3635
input: &'a [u8],
3736
}
@@ -91,7 +90,6 @@ impl<'a> Parse<'a> {
9190
}
9291

9392
/// Like `Parse`, but yields pairs of `String` instead of pairs of `Cow<str>`.
94-
#[derive(Debug)]
9593
pub struct ParseIntoOwned<'a> {
9694
inner: Parse<'a>,
9795
}
@@ -161,20 +159,10 @@ impl<'a> Iterator for ByteSerialize<'a> {
161159

162160
/// The [`application/x-www-form-urlencoded` serializer](
163161
/// https://url.spec.whatwg.org/#concept-urlencoded-serializer).
164-
#[derive(Debug)]
165-
pub struct Serializer<T: Target> {
162+
pub struct Serializer<'a, T: Target> {
166163
target: Option<T>,
167164
start_position: usize,
168-
encoding: EncodingOverride,
169-
custom_encoding: Option<SilentDebug<Box<dyn FnMut(&str) -> Cow<[u8]>>>>,
170-
}
171-
172-
struct SilentDebug<T>(T);
173-
174-
impl<T> fmt::Debug for SilentDebug<T> {
175-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
176-
f.write_str("…")
177-
}
165+
encoding: EncodingOverride<'a>,
178166
}
179167

180168
pub trait Target {
@@ -227,7 +215,7 @@ impl<'a> Target for ::UrlQuery<'a> {
227215
type Finished = &'a mut ::Url;
228216
}
229217

230-
impl<T: Target> Serializer<T> {
218+
impl<'a, T: Target> Serializer<'a, T> {
231219
/// Create a new `application/x-www-form-urlencoded` serializer for the given target.
232220
///
233221
/// If the target is non-empty,
@@ -246,8 +234,7 @@ impl<T: Target> Serializer<T> {
246234
Serializer {
247235
target: Some(target),
248236
start_position: start_position,
249-
encoding: EncodingOverride::utf8(),
250-
custom_encoding: None,
237+
encoding: None,
251238
}
252239
}
253240

@@ -260,18 +247,8 @@ impl<T: Target> Serializer<T> {
260247
}
261248

262249
/// Set the character encoding to be used for names and values before percent-encoding.
263-
#[cfg(feature = "query_encoding")]
264-
pub fn encoding_override(&mut self, new: Option<::encoding::EncodingRef>) -> &mut Self {
265-
self.encoding = EncodingOverride::from_opt_encoding(new).to_output_encoding();
266-
self
267-
}
268-
269-
/// Set the character encoding to be used for names and values before percent-encoding.
270-
pub fn custom_encoding_override<F>(&mut self, encode: F) -> &mut Self
271-
where
272-
F: FnMut(&str) -> Cow<[u8]> + 'static,
273-
{
274-
self.custom_encoding = Some(SilentDebug(Box::new(encode)));
250+
pub fn encoding_override(&mut self, new: EncodingOverride<'a>) -> &mut Self {
251+
self.encoding = new;
275252
self
276253
}
277254

@@ -283,7 +260,6 @@ impl<T: Target> Serializer<T> {
283260
string(&mut self.target),
284261
self.start_position,
285262
self.encoding,
286-
&mut self.custom_encoding,
287263
name,
288264
value,
289265
);
@@ -312,7 +288,6 @@ impl<T: Target> Serializer<T> {
312288
string,
313289
self.start_position,
314290
self.encoding,
315-
&mut self.custom_encoding,
316291
k.as_ref(),
317292
v.as_ref(),
318293
);
@@ -321,26 +296,6 @@ impl<T: Target> Serializer<T> {
321296
self
322297
}
323298

324-
/// Add a name/value pair whose name is `_charset_`
325-
/// and whose value is the character encoding’s name.
326-
/// (See the `encoding_override()` method.)
327-
///
328-
/// Panics if called after `.finish()`.
329-
#[cfg(feature = "query_encoding")]
330-
pub fn append_charset(&mut self) -> &mut Self {
331-
assert!(
332-
self.custom_encoding.is_none(),
333-
"Cannot use both custom_encoding_override() and append_charset()"
334-
);
335-
{
336-
let string = string(&mut self.target);
337-
append_separator_if_needed(string, self.start_position);
338-
string.push_str("_charset_=");
339-
string.push_str(self.encoding.name());
340-
}
341-
self
342-
}
343-
344299
/// If this serializer was constructed with a string, take and return that string.
345300
///
346301
/// ```rust
@@ -378,26 +333,15 @@ fn append_pair(
378333
string: &mut String,
379334
start_position: usize,
380335
encoding: EncodingOverride,
381-
custom_encoding: &mut Option<SilentDebug<Box<dyn FnMut(&str) -> Cow<[u8]>>>>,
382336
name: &str,
383337
value: &str,
384338
) {
385339
append_separator_if_needed(string, start_position);
386-
append_encoded(name, string, encoding, custom_encoding);
340+
append_encoded(name, string, encoding);
387341
string.push('=');
388-
append_encoded(value, string, encoding, custom_encoding);
342+
append_encoded(value, string, encoding);
389343
}
390344

391-
fn append_encoded(
392-
s: &str,
393-
string: &mut String,
394-
encoding: EncodingOverride,
395-
custom_encoding: &mut Option<SilentDebug<Box<dyn FnMut(&str) -> Cow<[u8]>>>>,
396-
) {
397-
let bytes = if let Some(SilentDebug(ref mut custom)) = *custom_encoding {
398-
custom(s)
399-
} else {
400-
encoding.encode(s.into())
401-
};
402-
string.extend(byte_serialize(&bytes));
345+
fn append_encoded(s: &str, string: &mut String, encoding: EncodingOverride) {
346+
string.extend(byte_serialize(&query_encoding::encode(encoding, s.into())))
403347
}

0 commit comments

Comments
 (0)