Skip to content

Commit 47e2286

Browse files
committed
Remove _charset_ support
CC whatwg/url@3fe9696
1 parent 896662b commit 47e2286

File tree

2 files changed

+6
-85
lines changed

2 files changed

+6
-85
lines changed

src/encoding.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ use std::borrow::Cow;
1717
use std::fmt::{self, Debug, Formatter};
1818

1919
#[cfg(feature = "query_encoding")]
20-
use self::encoding::label::encoding_from_whatwg_label;
20+
use self::encoding::types::EncoderTrap;
2121
#[cfg(feature = "query_encoding")]
2222
pub use self::encoding::types::EncodingRef;
23-
#[cfg(feature = "query_encoding")]
24-
use self::encoding::types::{DecoderTrap, EncoderTrap};
2523

2624
#[cfg(feature = "query_encoding")]
2725
#[derive(Copy, Clone)]
@@ -51,15 +49,6 @@ impl EncodingOverride {
5149
EncodingOverride { encoding: None }
5250
}
5351

54-
pub fn lookup(label: &[u8]) -> Option<Self> {
55-
// Don't use String::from_utf8_lossy since no encoding label contains U+FFFD
56-
// https://encoding.spec.whatwg.org/#names-and-labels
57-
::std::str::from_utf8(label)
58-
.ok()
59-
.and_then(encoding_from_whatwg_label)
60-
.map(Self::from_encoding)
61-
}
62-
6352
/// https://encoding.spec.whatwg.org/#get-an-output-encoding
6453
pub fn to_output_encoding(self) -> Self {
6554
if let Some(encoding) = self.encoding {
@@ -70,28 +59,13 @@ impl EncodingOverride {
7059
self
7160
}
7261

73-
pub fn is_utf8(&self) -> bool {
74-
self.encoding.is_none()
75-
}
76-
7762
pub fn name(&self) -> &'static str {
7863
match self.encoding {
7964
Some(encoding) => encoding.name(),
8065
None => "utf-8",
8166
}
8267
}
8368

84-
pub fn decode<'a>(&self, input: Cow<'a, [u8]>) -> Cow<'a, str> {
85-
match self.encoding {
86-
// `encoding.decode` never returns `Err` when called with `DecoderTrap::Replace`
87-
Some(encoding) => encoding
88-
.decode(&input, DecoderTrap::Replace)
89-
.unwrap()
90-
.into(),
91-
None => decode_utf8_lossy(input),
92-
}
93-
}
94-
9569
pub fn encode<'a>(&self, input: Cow<'a, str>) -> Cow<'a, [u8]> {
9670
match self.encoding {
9771
// `encoding.encode` never returns `Err` when called with `EncoderTrap::NcrEscape`
@@ -123,10 +97,6 @@ impl EncodingOverride {
12397
EncodingOverride
12498
}
12599

126-
pub fn decode<'a>(&self, input: Cow<'a, [u8]>) -> Cow<'a, str> {
127-
decode_utf8_lossy(input)
128-
}
129-
130100
pub fn encode<'a>(&self, input: Cow<'a, str>) -> Cow<'a, [u8]> {
131101
encode_utf8(input)
132102
}

src/form_urlencoded.rs

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! Converts between a string (such as an URL’s query string)
1414
//! and a sequence of (name, value) pairs.
1515
16-
use encoding::EncodingOverride;
16+
use encoding::{decode_utf8_lossy, EncodingOverride};
1717
use percent_encoding::{percent_decode, percent_encode_byte};
1818
use std::borrow::{Borrow, Cow};
1919
use std::fmt;
@@ -28,61 +28,12 @@ use std::str;
2828
/// converted to `[("#first", "%try%")]`.
2929
#[inline]
3030
pub fn parse(input: &[u8]) -> Parse {
31-
Parse {
32-
input: input,
33-
encoding: EncodingOverride::utf8(),
34-
}
31+
Parse { input: input }
3532
}
36-
37-
/// Convert a byte string in the `application/x-www-form-urlencoded` syntax
38-
/// into a iterator of (name, value) pairs.
39-
///
40-
/// Use `parse(input.as_bytes())` to parse a `&str` string.
41-
///
42-
/// This function is only available if the `query_encoding`
43-
/// [feature](http://doc.crates.io/manifest.html#the-features-section]) is enabled.
44-
///
45-
/// Arguments:
46-
///
47-
/// * `encoding_override`: The character encoding each name and values is decoded as
48-
/// after percent-decoding. Defaults to UTF-8.
49-
/// `EncodingRef` is defined in [rust-encoding](https://github.com/lifthrasiir/rust-encoding).
50-
/// * `use_charset`: The *use _charset_ flag*. If in doubt, set to `false`.
51-
#[cfg(feature = "query_encoding")]
52-
pub fn parse_with_encoding<'a>(
53-
input: &'a [u8],
54-
encoding_override: Option<::encoding::EncodingRef>,
55-
use_charset: bool,
56-
) -> Result<Parse<'a>, ()> {
57-
let mut encoding = EncodingOverride::from_opt_encoding(encoding_override);
58-
if !(encoding.is_utf8() || input.is_ascii()) {
59-
return Err(());
60-
}
61-
if use_charset {
62-
for sequence in input.split(|&b| b == b'&') {
63-
// No '+' in "_charset_" to replace with ' '.
64-
if sequence.starts_with(b"_charset_=") {
65-
let value = &sequence[b"_charset_=".len()..];
66-
// Skip replacing '+' with ' ' in value since no encoding label contains either:
67-
// https://encoding.spec.whatwg.org/#names-and-labels
68-
if let Some(e) = EncodingOverride::lookup(value) {
69-
encoding = e;
70-
break;
71-
}
72-
}
73-
}
74-
}
75-
Ok(Parse {
76-
input: input,
77-
encoding: encoding,
78-
})
79-
}
80-
8133
/// The return type of `parse()`.
8234
#[derive(Copy, Clone, Debug)]
8335
pub struct Parse<'a> {
8436
input: &'a [u8],
85-
encoding: EncodingOverride,
8637
}
8738

8839
impl<'a> Iterator for Parse<'a> {
@@ -102,14 +53,14 @@ impl<'a> Iterator for Parse<'a> {
10253
let mut split2 = sequence.splitn(2, |&b| b == b'=');
10354
let name = split2.next().unwrap();
10455
let value = split2.next().unwrap_or(&[][..]);
105-
return Some((decode(name, self.encoding), decode(value, self.encoding)));
56+
return Some((decode(name), decode(value)));
10657
}
10758
}
10859
}
10960

110-
fn decode(input: &[u8], encoding: EncodingOverride) -> Cow<str> {
61+
fn decode(input: &[u8]) -> Cow<str> {
11162
let replaced = replace_plus(input);
112-
encoding.decode(match percent_decode(&replaced).if_any() {
63+
decode_utf8_lossy(match percent_decode(&replaced).if_any() {
11364
Some(vec) => Cow::Owned(vec),
11465
None => replaced,
11566
})

0 commit comments

Comments
 (0)