mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Audit usages of unicode case-changing methods.
This commit is contained in:
parent
58fd2956b3
commit
23e5bfaf27
6 changed files with 30 additions and 28 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,17 +3875,16 @@ 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 token {
|
||||||
return match lower.as_ref() {
|
t if t.eq_ignore_ascii_case("never") | t.eq_ignore_ascii_case("no-referrer") => Some(ReferrerPolicy::NoReferrer),
|
||||||
"never" | "no-referrer" => Some(ReferrerPolicy::NoReferrer),
|
t if t.eq_ignore_ascii_case("default") | t.eq_ignore_ascii_case("no-referrer-when-downgrade") => Some(ReferrerPolicy::NoReferrerWhenDowngrade),
|
||||||
"default" | "no-referrer-when-downgrade" => Some(ReferrerPolicy::NoReferrerWhenDowngrade),
|
t if t.eq_ignore_ascii_case("origin") => Some(ReferrerPolicy::Origin),
|
||||||
"origin" => Some(ReferrerPolicy::Origin),
|
t if t.eq_ignore_ascii_case("same-origin") => Some(ReferrerPolicy::SameOrigin),
|
||||||
"same-origin" => Some(ReferrerPolicy::SameOrigin),
|
t if t.eq_ignore_ascii_case("strict-origin") => Some(ReferrerPolicy::StrictOrigin),
|
||||||
"strict-origin" => Some(ReferrerPolicy::StrictOrigin),
|
t if t.eq_ignore_ascii_case("strict-origin-when-cross-origin") => Some(ReferrerPolicy::StrictOriginWhenCrossOrigin),
|
||||||
"strict-origin-when-cross-origin" => Some(ReferrerPolicy::StrictOriginWhenCrossOrigin),
|
t if t.eq_ignore_ascii_case("origin-when-cross-origin") => Some(ReferrerPolicy::OriginWhenCrossOrigin),
|
||||||
"origin-when-cross-origin" => Some(ReferrerPolicy::OriginWhenCrossOrigin),
|
t if t.eq_ignore_ascii_case("always") | t.eq_ignore_ascii_case("unsafe-url") => Some(ReferrerPolicy::UnsafeUrl),
|
||||||
"always" | "unsafe-url" => Some(ReferrerPolicy::UnsafeUrl),
|
t if t.eq_ignore_ascii_case("") => Some(ReferrerPolicy::NoReferrer),
|
||||||
"" => Some(ReferrerPolicy::NoReferrer),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::activation::Activatable;
|
use dom::activation::Activatable;
|
||||||
|
use std::ascii::AsciiExt;
|
||||||
use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListMethods;
|
use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListMethods;
|
||||||
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding::HTMLAreaElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding::HTMLAreaElementMethods;
|
||||||
|
@ -240,13 +241,13 @@ 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 &shape {
|
||||||
"circle" => Shape::Circle,
|
s if s.eq_ignore_ascii_case("circle") => Shape::Circle,
|
||||||
"circ" => Shape::Circle,
|
s if s.eq_ignore_ascii_case("circ") => Shape::Circle,
|
||||||
"rectangle" => Shape::Rectangle,
|
s if s.eq_ignore_ascii_case("rectangle") => Shape::Rectangle,
|
||||||
"rect" => Shape::Rectangle,
|
s if s.eq_ignore_ascii_case("rect") => Shape::Rectangle,
|
||||||
"polygon" => Shape::Rectangle,
|
s if s.eq_ignore_ascii_case("polygon") => Shape::Rectangle,
|
||||||
"poly" => Shape::Polygon,
|
s if s.eq_ignore_ascii_case("poly") => Shape::Polygon,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
if elem.has_attribute(&"coords".into()) {
|
if elem.has_attribute(&"coords".into()) {
|
||||||
|
|
|
@ -377,9 +377,9 @@ impl HTMLElementMethods for HTMLElement {
|
||||||
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 = "data-".to_owned();
|
||||||
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('\x2d');
|
||||||
attr_name.extend(ch.to_lowercase());
|
attr_name.push(ch.to_ascii_lowercase());
|
||||||
} else {
|
} else {
|
||||||
attr_name.push(ch);
|
attr_name.push(ch);
|
||||||
}
|
}
|
||||||
|
@ -398,9 +398,7 @@ fn to_camel_case(name: &str) -> Option<DOMString> {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -410,7 +408,7 @@ fn to_camel_case(name: &str) -> Option<DOMString> {
|
||||||
//check for hyphen followed by character
|
//check for hyphen followed by character
|
||||||
if curr_char == '\x2d' {
|
if curr_char == '\x2d' {
|
||||||
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);
|
||||||
|
|
|
@ -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)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue