Skip to content
Permalink
Browse files

Audit usages of unicode case-changing methods.

  • Loading branch information
frewsxcv committed Jul 26, 2017
1 parent 58fd295 commit 23e5bfaf27312840092d9938bb99748a02e0d9bf
@@ -21,6 +21,7 @@ use net_traits::request::{Referrer, Request, RequestMode, ResponseTainting};
use net_traits::request::{Type, Origin, Window};
use net_traits::response::{Response, ResponseBody, ResponseType};
use servo_url::ServoUrl;
use std::ascii::AsciiExt;
use std::borrow::Cow;
use std::fmt;
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> {
raw.first()
.and_then(|v| str::from_utf8(v).ok())
.and_then(|s| match s.trim().to_lowercase().as_str() {
"nosniff" => Some(XContentTypeOptions),
_ => None
.and_then(|s| if s.trim().eq_ignore_ascii_case("nosniff") {
Some(XContentTypeOptions)
} else {
None
})
.ok_or(Error::Header)
}
@@ -16,6 +16,7 @@ use ipc_channel::ipc;
use net_traits::{CoreResourceMsg, IpcSend};
use net_traits::blob_url_store::{BlobBuf, get_blob_origin};
use net_traits::filemanager_thread::{FileManagerThreadMsg, ReadFileProgress, RelativePos};
use std::ascii::AsciiExt;
use std::mem;
use std::ops::Index;
use std::path::PathBuf;
@@ -381,7 +382,7 @@ impl BlobMethods for Blob {
/// see https://github.com/w3c/FileAPI/issues/43
fn normalize_type_string(s: &str) -> String {
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, ()> {
// Ok(_) => s_lower,
// 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
pub fn determine_policy_for_token(token: &str) -> Option<ReferrerPolicy> {
let lower = token.to_lowercase();
return match lower.as_ref() {
"never" | "no-referrer" => Some(ReferrerPolicy::NoReferrer),
"default" | "no-referrer-when-downgrade" => Some(ReferrerPolicy::NoReferrerWhenDowngrade),
"origin" => Some(ReferrerPolicy::Origin),
"same-origin" => Some(ReferrerPolicy::SameOrigin),
"strict-origin" => Some(ReferrerPolicy::StrictOrigin),
"strict-origin-when-cross-origin" => Some(ReferrerPolicy::StrictOriginWhenCrossOrigin),
"origin-when-cross-origin" => Some(ReferrerPolicy::OriginWhenCrossOrigin),
"always" | "unsafe-url" => Some(ReferrerPolicy::UnsafeUrl),
"" => Some(ReferrerPolicy::NoReferrer),
match token {
t if t.eq_ignore_ascii_case("never") | t.eq_ignore_ascii_case("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),
t if t.eq_ignore_ascii_case("origin") => Some(ReferrerPolicy::Origin),
t if t.eq_ignore_ascii_case("same-origin") => Some(ReferrerPolicy::SameOrigin),
t if t.eq_ignore_ascii_case("strict-origin") => Some(ReferrerPolicy::StrictOrigin),
t if t.eq_ignore_ascii_case("strict-origin-when-cross-origin") => Some(ReferrerPolicy::StrictOriginWhenCrossOrigin),
t if t.eq_ignore_ascii_case("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),
t if t.eq_ignore_ascii_case("") => Some(ReferrerPolicy::NoReferrer),
_ => None,
}
}
@@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use dom::activation::Activatable;
use std::ascii::AsciiExt;
use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListMethods;
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding;
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding::HTMLAreaElementMethods;
@@ -240,13 +241,13 @@ impl HTMLAreaElement {
pub fn get_shape_from_coords(&self) -> Option<Area> {
let elem = self.upcast::<Element>();
let shape = elem.get_string_attribute(&"shape".into());
let shp: Shape = match shape.to_lowercase().as_ref() {
"circle" => Shape::Circle,
"circ" => Shape::Circle,
"rectangle" => Shape::Rectangle,
"rect" => Shape::Rectangle,
"polygon" => Shape::Rectangle,
"poly" => Shape::Polygon,
let shp: Shape = match &shape {
s if s.eq_ignore_ascii_case("circle") => Shape::Circle,
s if s.eq_ignore_ascii_case("circ") => Shape::Circle,
s if s.eq_ignore_ascii_case("rectangle") => Shape::Rectangle,
s if s.eq_ignore_ascii_case("rect") => Shape::Rectangle,
s if s.eq_ignore_ascii_case("polygon") => Shape::Rectangle,
s if s.eq_ignore_ascii_case("poly") => Shape::Polygon,
_ => return None,
};
if elem.has_attribute(&"coords".into()) {
@@ -377,9 +377,9 @@ impl HTMLElementMethods for HTMLElement {
fn to_snake_case(name: DOMString) -> DOMString {
let mut attr_name = "data-".to_owned();
for ch in name.chars() {
if ch.is_uppercase() {
if ch.is_ascii_uppercase() {
attr_name.push('\x2d');
attr_name.extend(ch.to_lowercase());
attr_name.push(ch.to_ascii_lowercase());
} else {
attr_name.push(ch);
}
@@ -398,9 +398,7 @@ fn to_camel_case(name: &str) -> Option<DOMString> {
return None;
}
let name = &name[5..];
let has_uppercase = name.chars().any(|curr_char| {
curr_char.is_ascii() && curr_char.is_uppercase()
});
let has_uppercase = name.chars().any(|curr_char| curr_char.is_ascii_uppercase());
if has_uppercase {
return None;
}
@@ -410,7 +408,7 @@ fn to_camel_case(name: &str) -> Option<DOMString> {
//check for hyphen followed by character
if curr_char == '\x2d' {
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());
} else {
result.push(curr_char);
@@ -2,6 +2,7 @@
* 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/. */

#![feature(ascii_ctype)]
#![feature(box_syntax)]
#![feature(conservative_impl_trait)]
#![feature(const_fn)]

0 comments on commit 23e5bfa

Please sign in to comment.
You can’t perform that action at this time.