mirror of
https://github.com/servo/servo.git
synced 2025-06-21 07:38:59 +01:00
Auto merge of #17883 - frewsxcv:frewsxcxv-lowercase, r=SimonSapin
Audit usages of unicode case-changing methods. Part of https://github.com/servo/servo/issues/17777. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17883) <!-- Reviewable:end -->
This commit is contained in:
commit
5fff90c73f
10 changed files with 46 additions and 48 deletions
|
@ -21,6 +21,7 @@ use net_traits::request::{Referrer, Request, RequestMode, ResponseTainting};
|
||||||
use net_traits::request::{Type, Origin, Window};
|
use net_traits::request::{Type, Origin, Window};
|
||||||
use net_traits::response::{Response, ResponseBody, ResponseType};
|
use net_traits::response::{Response, ResponseBody, ResponseType};
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
|
use std::ascii::AsciiExt;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
@ -514,9 +515,10 @@ pub fn should_be_blocked_due_to_nosniff(request_type: Type, response_headers: &H
|
||||||
fn parse_header(raw: &[Vec<u8>]) -> HyperResult<Self> {
|
fn parse_header(raw: &[Vec<u8>]) -> HyperResult<Self> {
|
||||||
raw.first()
|
raw.first()
|
||||||
.and_then(|v| str::from_utf8(v).ok())
|
.and_then(|v| str::from_utf8(v).ok())
|
||||||
.and_then(|s| match s.trim().to_lowercase().as_str() {
|
.and_then(|s| if s.trim().eq_ignore_ascii_case("nosniff") {
|
||||||
"nosniff" => Some(XContentTypeOptions),
|
Some(XContentTypeOptions)
|
||||||
_ => None
|
} else {
|
||||||
|
None
|
||||||
})
|
})
|
||||||
.ok_or(Error::Header)
|
.ok_or(Error::Header)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ use ipc_channel::ipc;
|
||||||
use net_traits::{CoreResourceMsg, IpcSend};
|
use net_traits::{CoreResourceMsg, IpcSend};
|
||||||
use net_traits::blob_url_store::{BlobBuf, get_blob_origin};
|
use net_traits::blob_url_store::{BlobBuf, get_blob_origin};
|
||||||
use net_traits::filemanager_thread::{FileManagerThreadMsg, ReadFileProgress, RelativePos};
|
use net_traits::filemanager_thread::{FileManagerThreadMsg, ReadFileProgress, RelativePos};
|
||||||
|
use std::ascii::AsciiExt;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::Index;
|
use std::ops::Index;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -381,7 +382,7 @@ impl BlobMethods for Blob {
|
||||||
/// see https://github.com/w3c/FileAPI/issues/43
|
/// see https://github.com/w3c/FileAPI/issues/43
|
||||||
fn normalize_type_string(s: &str) -> String {
|
fn normalize_type_string(s: &str) -> String {
|
||||||
if is_ascii_printable(s) {
|
if is_ascii_printable(s) {
|
||||||
let s_lower = s.to_lowercase();
|
let s_lower = s.to_ascii_lowercase();
|
||||||
// match s_lower.parse() as Result<Mime, ()> {
|
// match s_lower.parse() as Result<Mime, ()> {
|
||||||
// Ok(_) => s_lower,
|
// Ok(_) => s_lower,
|
||||||
// Err(_) => "".to_string()
|
// Err(_) => "".to_string()
|
||||||
|
|
|
@ -3875,8 +3875,7 @@ fn update_with_current_time_ms(marker: &Cell<u64>) {
|
||||||
|
|
||||||
/// https://w3c.github.io/webappsec-referrer-policy/#determine-policy-for-token
|
/// https://w3c.github.io/webappsec-referrer-policy/#determine-policy-for-token
|
||||||
pub fn determine_policy_for_token(token: &str) -> Option<ReferrerPolicy> {
|
pub fn determine_policy_for_token(token: &str) -> Option<ReferrerPolicy> {
|
||||||
let lower = token.to_lowercase();
|
match_ignore_ascii_case! { token,
|
||||||
return match lower.as_ref() {
|
|
||||||
"never" | "no-referrer" => Some(ReferrerPolicy::NoReferrer),
|
"never" | "no-referrer" => Some(ReferrerPolicy::NoReferrer),
|
||||||
"default" | "no-referrer-when-downgrade" => Some(ReferrerPolicy::NoReferrerWhenDowngrade),
|
"default" | "no-referrer-when-downgrade" => Some(ReferrerPolicy::NoReferrerWhenDowngrade),
|
||||||
"origin" => Some(ReferrerPolicy::Origin),
|
"origin" => Some(ReferrerPolicy::Origin),
|
||||||
|
|
|
@ -240,7 +240,7 @@ impl HTMLAreaElement {
|
||||||
pub fn get_shape_from_coords(&self) -> Option<Area> {
|
pub fn get_shape_from_coords(&self) -> Option<Area> {
|
||||||
let elem = self.upcast::<Element>();
|
let elem = self.upcast::<Element>();
|
||||||
let shape = elem.get_string_attribute(&"shape".into());
|
let shape = elem.get_string_attribute(&"shape".into());
|
||||||
let shp: Shape = match shape.to_lowercase().as_ref() {
|
let shp: Shape = match_ignore_ascii_case! { &shape,
|
||||||
"circle" => Shape::Circle,
|
"circle" => Shape::Circle,
|
||||||
"circ" => Shape::Circle,
|
"circ" => Shape::Circle,
|
||||||
"rectangle" => Shape::Rectangle,
|
"rectangle" => Shape::Rectangle,
|
||||||
|
|
|
@ -32,7 +32,6 @@ use dom::virtualmethods::VirtualMethods;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use html5ever::{LocalName, Prefix};
|
use html5ever::{LocalName, Prefix};
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use std::borrow::ToOwned;
|
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use style::attr::AttrValue;
|
use style::attr::AttrValue;
|
||||||
|
@ -374,12 +373,16 @@ impl HTMLElementMethods for HTMLElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-data-*
|
// https://html.spec.whatwg.org/multipage/#attr-data-*
|
||||||
|
|
||||||
|
static DATA_PREFIX: &str = "data-";
|
||||||
|
static DATA_HYPHEN_SEPARATOR: char = '\x2d';
|
||||||
|
|
||||||
fn to_snake_case(name: DOMString) -> DOMString {
|
fn to_snake_case(name: DOMString) -> DOMString {
|
||||||
let mut attr_name = "data-".to_owned();
|
let mut attr_name = String::with_capacity(name.len() + DATA_PREFIX.len());
|
||||||
|
attr_name.push_str(DATA_PREFIX);
|
||||||
for ch in name.chars() {
|
for ch in name.chars() {
|
||||||
if ch.is_uppercase() {
|
if ch.is_ascii_uppercase() {
|
||||||
attr_name.push('\x2d');
|
attr_name.push(DATA_HYPHEN_SEPARATOR);
|
||||||
attr_name.extend(ch.to_lowercase());
|
attr_name.push(ch.to_ascii_lowercase());
|
||||||
} else {
|
} else {
|
||||||
attr_name.push(ch);
|
attr_name.push(ch);
|
||||||
}
|
}
|
||||||
|
@ -394,23 +397,21 @@ fn to_snake_case(name: DOMString) -> DOMString {
|
||||||
// without the data prefix.
|
// without the data prefix.
|
||||||
|
|
||||||
fn to_camel_case(name: &str) -> Option<DOMString> {
|
fn to_camel_case(name: &str) -> Option<DOMString> {
|
||||||
if !name.starts_with("data-") {
|
if !name.starts_with(DATA_PREFIX) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let name = &name[5..];
|
let name = &name[5..];
|
||||||
let has_uppercase = name.chars().any(|curr_char| {
|
let has_uppercase = name.chars().any(|curr_char| curr_char.is_ascii_uppercase());
|
||||||
curr_char.is_ascii() && curr_char.is_uppercase()
|
|
||||||
});
|
|
||||||
if has_uppercase {
|
if has_uppercase {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let mut result = "".to_owned();
|
let mut result = String::with_capacity(name.len().saturating_sub(DATA_PREFIX.len()));
|
||||||
let mut name_chars = name.chars();
|
let mut name_chars = name.chars();
|
||||||
while let Some(curr_char) = name_chars.next() {
|
while let Some(curr_char) = name_chars.next() {
|
||||||
//check for hyphen followed by character
|
//check for hyphen followed by character
|
||||||
if curr_char == '\x2d' {
|
if curr_char == DATA_HYPHEN_SEPARATOR {
|
||||||
if let Some(next_char) = name_chars.next() {
|
if let Some(next_char) = name_chars.next() {
|
||||||
if next_char.is_ascii() && next_char.is_lowercase() {
|
if next_char.is_ascii_lowercase() {
|
||||||
result.push(next_char.to_ascii_uppercase());
|
result.push(next_char.to_ascii_uppercase());
|
||||||
} else {
|
} else {
|
||||||
result.push(curr_char);
|
result.push(curr_char);
|
||||||
|
|
|
@ -38,7 +38,6 @@ use net_traits::request::Request as NetTraitsRequest;
|
||||||
use net_traits::request::RequestMode as NetTraitsRequestMode;
|
use net_traits::request::RequestMode as NetTraitsRequestMode;
|
||||||
use net_traits::request::Type as NetTraitsRequestType;
|
use net_traits::request::Type as NetTraitsRequestType;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use std::ascii::AsciiExt;
|
|
||||||
use std::cell::{Cell, Ref};
|
use std::cell::{Cell, Ref};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
@ -453,15 +452,16 @@ fn net_request_from_global(global: &GlobalScope,
|
||||||
|
|
||||||
// https://fetch.spec.whatwg.org/#concept-method-normalize
|
// https://fetch.spec.whatwg.org/#concept-method-normalize
|
||||||
fn normalize_method(m: &str) -> HttpMethod {
|
fn normalize_method(m: &str) -> HttpMethod {
|
||||||
match m {
|
match_ignore_ascii_case! { m,
|
||||||
m if m.eq_ignore_ascii_case("DELETE") => HttpMethod::Delete,
|
"delete" => return HttpMethod::Delete,
|
||||||
m if m.eq_ignore_ascii_case("GET") => HttpMethod::Get,
|
"get" => return HttpMethod::Get,
|
||||||
m if m.eq_ignore_ascii_case("HEAD") => HttpMethod::Head,
|
"head" => return HttpMethod::Head,
|
||||||
m if m.eq_ignore_ascii_case("OPTIONS") => HttpMethod::Options,
|
"options" => return HttpMethod::Options,
|
||||||
m if m.eq_ignore_ascii_case("POST") => HttpMethod::Post,
|
"post" => return HttpMethod::Post,
|
||||||
m if m.eq_ignore_ascii_case("PUT") => HttpMethod::Put,
|
"put" => return HttpMethod::Put,
|
||||||
m => HttpMethod::Extension(m.to_string()),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
HttpMethod::Extension(m.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://fetch.spec.whatwg.org/#concept-method
|
// https://fetch.spec.whatwg.org/#concept-method
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#![feature(ascii_ctype)]
|
||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
#![feature(conservative_impl_trait)]
|
#![feature(conservative_impl_trait)]
|
||||||
#![feature(const_fn)]
|
#![feature(const_fn)]
|
||||||
|
|
|
@ -1586,10 +1586,10 @@ where Impl: SelectorImpl, F: FnOnce(i32, i32) -> Component<Impl> {
|
||||||
/// double-colon syntax, which can be used for all pseudo-elements).
|
/// double-colon syntax, which can be used for all pseudo-elements).
|
||||||
pub fn is_css2_pseudo_element<'i>(name: &CowRcStr<'i>) -> bool {
|
pub fn is_css2_pseudo_element<'i>(name: &CowRcStr<'i>) -> bool {
|
||||||
// ** Do not add to this list! **
|
// ** Do not add to this list! **
|
||||||
return name.eq_ignore_ascii_case("before") ||
|
match_ignore_ascii_case! { name,
|
||||||
name.eq_ignore_ascii_case("after") ||
|
"before" | "after" | "first-line" | "first-letter" => true,
|
||||||
name.eq_ignore_ascii_case("first-line") ||
|
_ => false,
|
||||||
name.eq_ignore_ascii_case("first-letter");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a simple selector other than a type selector.
|
/// Parse a simple selector other than a type selector.
|
||||||
|
|
|
@ -12,7 +12,6 @@ use cssparser::{Delimiter, Parser, Token, ParserInput};
|
||||||
use parser::ParserContext;
|
use parser::ParserContext;
|
||||||
use selectors::parser::SelectorParseError;
|
use selectors::parser::SelectorParseError;
|
||||||
use serialize_comma_separated_list;
|
use serialize_comma_separated_list;
|
||||||
use std::ascii::AsciiExt;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::{ToCss, ParseError, StyleParseError};
|
use style_traits::{ToCss, ParseError, StyleParseError};
|
||||||
|
|
||||||
|
@ -146,20 +145,15 @@ pub enum MediaQueryType {
|
||||||
|
|
||||||
impl MediaQueryType {
|
impl MediaQueryType {
|
||||||
fn parse(ident: &str) -> Result<Self, ()> {
|
fn parse(ident: &str) -> Result<Self, ()> {
|
||||||
if ident.eq_ignore_ascii_case("all") {
|
match_ignore_ascii_case! { ident,
|
||||||
return Ok(MediaQueryType::All);
|
"all" => return Ok(MediaQueryType::All),
|
||||||
}
|
// From https://drafts.csswg.org/mediaqueries/#mq-syntax:
|
||||||
|
//
|
||||||
// From https://drafts.csswg.org/mediaqueries/#mq-syntax:
|
// The <media-type> production does not include the keywords only,
|
||||||
//
|
// not, and, and or.
|
||||||
// The <media-type> production does not include the keywords only,
|
"not" | "or" | "and" | "only" => return Err(()),
|
||||||
// not, and, and or.
|
_ => (),
|
||||||
if ident.eq_ignore_ascii_case("not") ||
|
};
|
||||||
ident.eq_ignore_ascii_case("or") ||
|
|
||||||
ident.eq_ignore_ascii_case("and") ||
|
|
||||||
ident.eq_ignore_ascii_case("only") {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(match MediaType::parse(ident) {
|
Ok(match MediaType::parse(ident) {
|
||||||
Some(media_type) => MediaQueryType::Known(media_type),
|
Some(media_type) => MediaQueryType::Known(media_type),
|
||||||
|
|
|
@ -151,7 +151,7 @@ fn where_predicate(ty: syn::Ty) -> syn::WherePredicate {
|
||||||
|
|
||||||
/// Transforms "FooBar" to "foo-bar".
|
/// Transforms "FooBar" to "foo-bar".
|
||||||
///
|
///
|
||||||
/// If the first Camel segment is "Moz"" or "Webkit", the result string
|
/// If the first Camel segment is "Moz" or "Webkit", the result string
|
||||||
/// is prepended with "-".
|
/// is prepended with "-".
|
||||||
fn to_css_identifier(mut camel_case: &str) -> String {
|
fn to_css_identifier(mut camel_case: &str) -> String {
|
||||||
camel_case = camel_case.trim_right_matches('_');
|
camel_case = camel_case.trim_right_matches('_');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue