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:
bors-servo 2017-08-02 03:01:26 -05:00 committed by GitHub
commit 5fff90c73f
10 changed files with 46 additions and 48 deletions

View file

@ -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()

View file

@ -3875,8 +3875,7 @@ 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() {
match_ignore_ascii_case! { token,
"never" | "no-referrer" => Some(ReferrerPolicy::NoReferrer),
"default" | "no-referrer-when-downgrade" => Some(ReferrerPolicy::NoReferrerWhenDowngrade),
"origin" => Some(ReferrerPolicy::Origin),

View file

@ -240,7 +240,7 @@ 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() {
let shp: Shape = match_ignore_ascii_case! { &shape,
"circle" => Shape::Circle,
"circ" => Shape::Circle,
"rectangle" => Shape::Rectangle,

View file

@ -32,7 +32,6 @@ use dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::default::Default;
use std::rc::Rc;
use style::attr::AttrValue;
@ -374,12 +373,16 @@ impl HTMLElementMethods for HTMLElement {
// 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 {
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() {
if ch.is_uppercase() {
attr_name.push('\x2d');
attr_name.extend(ch.to_lowercase());
if ch.is_ascii_uppercase() {
attr_name.push(DATA_HYPHEN_SEPARATOR);
attr_name.push(ch.to_ascii_lowercase());
} else {
attr_name.push(ch);
}
@ -394,23 +397,21 @@ fn to_snake_case(name: DOMString) -> DOMString {
// without the data prefix.
fn to_camel_case(name: &str) -> Option<DOMString> {
if !name.starts_with("data-") {
if !name.starts_with(DATA_PREFIX) {
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;
}
let mut result = "".to_owned();
let mut result = String::with_capacity(name.len().saturating_sub(DATA_PREFIX.len()));
let mut name_chars = name.chars();
while let Some(curr_char) = name_chars.next() {
//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 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);

View file

@ -38,7 +38,6 @@ use net_traits::request::Request as NetTraitsRequest;
use net_traits::request::RequestMode as NetTraitsRequestMode;
use net_traits::request::Type as NetTraitsRequestType;
use servo_url::ServoUrl;
use std::ascii::AsciiExt;
use std::cell::{Cell, Ref};
use std::rc::Rc;
@ -453,15 +452,16 @@ fn net_request_from_global(global: &GlobalScope,
// https://fetch.spec.whatwg.org/#concept-method-normalize
fn normalize_method(m: &str) -> HttpMethod {
match m {
m if m.eq_ignore_ascii_case("DELETE") => HttpMethod::Delete,
m if m.eq_ignore_ascii_case("GET") => HttpMethod::Get,
m if m.eq_ignore_ascii_case("HEAD") => HttpMethod::Head,
m if m.eq_ignore_ascii_case("OPTIONS") => HttpMethod::Options,
m if m.eq_ignore_ascii_case("POST") => HttpMethod::Post,
m if m.eq_ignore_ascii_case("PUT") => HttpMethod::Put,
m => HttpMethod::Extension(m.to_string()),
match_ignore_ascii_case! { m,
"delete" => return HttpMethod::Delete,
"get" => return HttpMethod::Get,
"head" => return HttpMethod::Head,
"options" => return HttpMethod::Options,
"post" => return HttpMethod::Post,
"put" => return HttpMethod::Put,
_ => (),
}
HttpMethod::Extension(m.to_string())
}
// https://fetch.spec.whatwg.org/#concept-method

View file

@ -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)]