Skip to content

Commit

Permalink
Audit usages of unicode case-changing methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Jul 26, 2017
1 parent 58fd295 commit 23e5bfa
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 28 deletions.
8 changes: 5 additions & 3 deletions components/net/fetch/methods.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion components/script/dom/blob.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
21 changes: 10 additions & 11 deletions components/script/dom/document.rs
Expand Up @@ -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,
}
}
Expand Down
15 changes: 8 additions & 7 deletions components/script/dom/htmlareaelement.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
10 changes: 4 additions & 6 deletions components/script/dom/htmlelement.rs
Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions components/script/lib.rs
Expand Up @@ -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)]
Expand Down

0 comments on commit 23e5bfa

Please sign in to comment.