Skip to content

Commit

Permalink
Merge pull request #1 from dmski/master
Browse files Browse the repository at this point in the history
Made rust-url compile with rust master
  • Loading branch information
SimonSapin committed Apr 9, 2014
2 parents 7592e78 + 491c166 commit 350bd6b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions form_urlencoded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn parse_bytes(input: &[u8], encoding_override: Option<EncodingRef>,

#[inline]
fn replace_plus(input: &[u8]) -> ~[u8] {
input.iter().map(|&b| if b == '+' as u8 { ' ' as u8 } else { b }).to_owned_vec()
input.iter().map(|&b| if b == '+' as u8 { ' ' as u8 } else { b }).collect()
}

#[inline]
Expand All @@ -71,7 +71,7 @@ pub fn parse_bytes(input: &[u8], encoding_override: Option<EncodingRef>,

Some(pairs.move_iter().map(
|(name, value)| (decode(name, encoding_override), decode(value, encoding_override))
).to_owned_vec())
).collect())
}


Expand Down
2 changes: 1 addition & 1 deletion parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ fn parse_path<'a>(base_path: ~[~str], input: &'a str, full_url: bool, in_file_sc
let lower = path_part.to_ascii_lower();
match lower.as_slice() {
".." | ".%2e" | "%2e." | "%2e%2e" => {
path.pop_opt();
path.pop();
if !ends_with_slash {
path.push(~"");
}
Expand Down
22 changes: 11 additions & 11 deletions punycode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.


use std::u32;
use std::char;
use std::str;


// Bootstring parameters for Punycode
static BASE: u32 = 36;
static T_MIN: u32 = 1;
Expand Down Expand Up @@ -46,7 +44,7 @@ pub fn decode(input: &str) -> Option<~[char]> {
let (mut output, input) = match input.rfind(DELIMITER) {
None => (~[], input),
Some(position) => (
input.slice_to(position).chars().to_owned_vec(),
input.slice_to(position).chars().collect(),
if position > 0 { input.slice_from(position + 1) } else { input }
)
};
Expand All @@ -71,7 +69,7 @@ pub fn decode(input: &str) -> Option<~[char]> {
byte @ 0x61 .. 0x7A => byte - 0x61, // a..z
_ => return None
} as u32;
if digit > (u32::max_value - i) / weight {
if digit > (u32::MAX - i) / weight {
return None // Overflow
}
i += digit * weight;
Expand All @@ -81,7 +79,7 @@ pub fn decode(input: &str) -> Option<~[char]> {
if digit < t {
break
}
if weight > u32::max_value / (BASE - t) {
if weight > u32::MAX / (BASE - t) {
return None // Overflow
}
weight *= BASE - t;
Expand All @@ -93,7 +91,7 @@ pub fn decode(input: &str) -> Option<~[char]> {
}
let length = output.len() as u32;
bias = adapt(i - previous_i, length + 1, previous_i == 0);
if i / (length + 1) > u32::max_value - code_point {
if i / (length + 1) > u32::MAX - code_point {
return None // Overflow
}
// i was supposed to wrap around from length+1 to 0,
Expand All @@ -118,7 +116,7 @@ pub fn encode(input: &[char]) -> Option<~str> {
// Handle "basic" (ASCII) code points. They are encoded as-is.
let output_bytes = input.iter().filter_map(|&c|
if c.is_ascii() { Some(c as u8) } else { None }
).to_owned_vec();
).collect();
let mut output = unsafe { str::raw::from_utf8_owned(output_bytes) };
let basic_length = output.len() as u32;
if basic_length > 0 {
Expand All @@ -134,7 +132,7 @@ pub fn encode(input: &[char]) -> Option<~str> {
// Find the next larger one.
let min_code_point = input.iter().map(|&c| c as u32)
.filter(|&c| c >= code_point).min().unwrap();
if min_code_point - code_point > (u32::max_value - delta) / (processed + 1) {
if min_code_point - code_point > (u32::MAX - delta) / (processed + 1) {
return None // Overflow
}
// Increase delta to advance the decoder’s <code_point,i> state to <min_code_point,0>
Expand Down Expand Up @@ -192,7 +190,7 @@ fn value_to_digit(value: u32, output: &mut ~str) {
mod tests {
use super::{decode, encode};
use std::str::from_chars;
use extra::json::{from_str, List, Object, String};
use serialize::json::{from_str, List, Object, String};

fn one_test(description: &str, decoded: &str, encoded: &str) {
match decode(encoded) {
Expand All @@ -203,9 +201,11 @@ mod tests {
format!("Incorrect decoding of {:?}:\n {:?}\n!= {:?}\n{}",
encoded, result.as_slice(), decoded, description))
}
}
}

let dec_chars: ~[char] = decoded.chars().collect();

match encode(decoded.chars().to_owned_vec()) {
match encode(dec_chars) {
None => fail!("Encoding {:?} failed.", decoded),
Some(result) => {
assert!(result.as_slice() == encoded,
Expand Down
6 changes: 3 additions & 3 deletions tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ fn parse_test_data(input: &str) -> ~[Test] {
if line == "" || line[0] == ('#' as u8) {
continue
}
let mut pieces = line.split(' ').to_owned_vec();
let input = unescape(pieces.shift());
let mut pieces: ~[&str] = line.split(' ').collect();
let input = unescape(pieces.shift().unwrap());
let mut test = Test {
input: input,
base: if pieces.is_empty() || pieces[0] == "" {
tests[tests.len() - 1].base.to_owned()
} else {
unescape(pieces.shift())
unescape(pieces.shift().unwrap())
},
scheme: None,
username: ~"",
Expand Down
17 changes: 9 additions & 8 deletions url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![crate_id = "url#0.1"]
#![crate_type = "lib"]
#![feature(macro_rules)]

#[crate_id = "url#0.1"];
#[crate_type = "lib"];
#[feature(macro_rules)];


extern mod encoding;
extern crate encoding;

#[cfg(test)]
extern mod extra;
extern crate serialize;

use std::str;
use std::cmp;

use std::num::ToStrRadix;

use encoding::Encoding;
use encoding::all::UTF_8;
Expand Down Expand Up @@ -228,7 +229,7 @@ impl Ipv6Address {
continue
}
let start = i;
let end = len.min(&(start + 4));
let end = cmp::min(len, start + 4);
let mut value = 0u16;
while i < end {
match from_hex(input[i]) {
Expand Down

0 comments on commit 350bd6b

Please sign in to comment.